summaryrefslogtreecommitdiff
path: root/bench/src
diff options
context:
space:
mode:
authorGravatar Sam Atman2025-07-08 12:15:32 -0400
committerGravatar Sam Atman2025-07-08 12:15:32 -0400
commit9427a9e53aaa29ee071f4dcb35b809a699d75aa9 (patch)
tree2607c185fd8053b84d60041fadc35c05a0225d34 /bench/src
parentMerge pull request 'Fix benchmarks' (#56) from jacobsandlund/zg:benchmarks in... (diff)
parentAdd Words.zig example to README (diff)
downloadzg-master.tar.gz
zg-master.tar.xz
zg-master.zip
Merge branch 'develop-next'HEADv0.14.1master
Diffstat (limited to 'bench/src')
-rw-r--r--bench/src/tests.zig222
-rw-r--r--bench/src/zg_case.zig43
-rw-r--r--bench/src/zg_caseless.zig54
-rw-r--r--bench/src/zg_codepoint.zig27
-rw-r--r--bench/src/zg_grapheme.zig28
-rw-r--r--bench/src/zg_normalize.zig75
-rw-r--r--bench/src/zg_width.zig32
-rw-r--r--bench/src/ziglyph_case.zig41
-rw-r--r--bench/src/ziglyph_caseless.zig35
-rw-r--r--bench/src/ziglyph_codepoint.zig27
-rw-r--r--bench/src/ziglyph_grapheme.zig27
-rw-r--r--bench/src/ziglyph_normalizer.zig75
-rw-r--r--bench/src/ziglyph_width.zig30
13 files changed, 0 insertions, 716 deletions
diff --git a/bench/src/tests.zig b/bench/src/tests.zig
deleted file mode 100644
index cf62709..0000000
--- a/bench/src/tests.zig
+++ /dev/null
@@ -1,222 +0,0 @@
1const std = @import("std");
2const testing = std.testing;
3const expect = testing.expect;
4const expectEqual = testing.expectEqual;
5const expectEqualStrings = testing.expectEqualStrings;
6
7const allocator = testing.allocator;
8
9const GeneralCategories = @import("GeneralCategories");
10
11test GeneralCategories {
12 const gen_cat = try GeneralCategories.init(allocator);
13 defer gen_cat.deinit(allocator);
14
15 try expect(gen_cat.gc('A') == .Lu); // Lu: uppercase letter
16 try expect(gen_cat.gc('3') == .Nd); // Nd: Decimal number
17 try expect(gen_cat.isControl(0));
18 try expect(gen_cat.isLetter('z'));
19 try expect(gen_cat.isMark('\u{301}'));
20 try expect(gen_cat.isNumber('3'));
21 try expect(gen_cat.isPunctuation('['));
22 try expect(gen_cat.isSeparator(' '));
23 try expect(gen_cat.isSymbol('©'));
24}
25
26const Properties = @import("Properties");
27
28test Properties {
29 const props = try Properties.init(allocator);
30 defer props.deinit(allocator);
31
32 try expect(props.isMath('+'));
33 try expect(props.isAlphabetic('Z'));
34 try expect(props.isWhitespace(' '));
35 try expect(props.isHexDigit('f'));
36 try expect(!props.isHexDigit('z'));
37
38 try expect(props.isDiacritic('\u{301}'));
39 try expect(props.isIdStart('Z')); // Identifier start character
40 try expect(!props.isIdStart('1'));
41 try expect(props.isIdContinue('1'));
42 try expect(props.isXidStart('\u{b33}')); // Extended identifier start character
43 try expect(props.isXidContinue('\u{e33}'));
44 try expect(!props.isXidStart('1'));
45
46 // Note surprising Unicode numeric types!
47 try expect(props.isNumeric('\u{277f}'));
48 try expect(!props.isNumeric('3'));
49 try expect(props.isDigit('\u{2070}'));
50 try expect(!props.isDigit('3'));
51 try expect(props.isDecimal('3'));
52}
53
54const LetterCasing = @import("LetterCasing");
55
56test LetterCasing {
57 const case = try LetterCasing.init(allocator);
58 defer case.deinit(allocator);
59
60 try expect(case.isUpper('A'));
61 try expect('A' == case.toUpper('a'));
62 try expect(case.isLower('a'));
63 try expect('a' == case.toLower('A'));
64
65 try expect(case.isCased('É'));
66 try expect(!case.isCased('3'));
67
68 try expect(case.isUpperStr("HELLO 123!"));
69 const ucased = try case.toUpperStr(allocator, "hello 123");
70 defer allocator.free(ucased);
71 try expectEqualStrings("HELLO 123", ucased);
72
73 try expect(case.isLowerStr("hello 123!"));
74 const lcased = try case.toLowerStr(allocator, "HELLO 123");
75 defer allocator.free(lcased);
76 try expectEqualStrings("hello 123", lcased);
77}
78
79const Normalize = @import("Normalize");
80
81test Normalize {
82 const normalize = try Normalize.init(allocator);
83 defer normalize.deinit(allocator);
84
85 // NFD: Canonical decomposition
86 const nfd_result = try normalize.nfd(allocator, "Héllo World! \u{3d3}");
87 defer nfd_result.deinit(allocator);
88 try expectEqualStrings("He\u{301}llo World! \u{3d2}\u{301}", nfd_result.slice);
89
90 // NFKD: Compatibility decomposition
91 const nfkd_result = try normalize.nfkd(allocator, "Héllo World! \u{3d3}");
92 defer nfkd_result.deinit(allocator);
93 try expectEqualStrings("He\u{301}llo World! \u{3a5}\u{301}", nfkd_result.slice);
94
95 // NFC: Canonical composition
96 const nfc_result = try normalize.nfc(allocator, "Complex char: \u{3D2}\u{301}");
97 defer nfc_result.deinit(allocator);
98 try expectEqualStrings("Complex char: \u{3D3}", nfc_result.slice);
99
100 // NFKC: Compatibility composition
101 const nfkc_result = try normalize.nfkc(allocator, "Complex char: \u{03A5}\u{0301}");
102 defer nfkc_result.deinit(allocator);
103 try expectEqualStrings("Complex char: \u{038E}", nfkc_result.slice);
104
105 // Test for equality of two strings after normalizing to NFC.
106 try expect(try normalize.eql(allocator, "foé", "foe\u{0301}"));
107 try expect(try normalize.eql(allocator, "foϓ", "fo\u{03D2}\u{0301}"));
108}
109
110const CaseFolding = @import("CaseFolding");
111
112test CaseFolding {
113 const case_fold = try CaseFolding.init(allocator);
114 defer case_fold.deinit(allocator);
115
116 // compatCaselessMatch provides the deepest level of caseless
117 // matching because it decomposes and composes fully to NFKC.
118 const a = "Héllo World! \u{3d3}";
119 const b = "He\u{301}llo World! \u{3a5}\u{301}";
120 try expect(try case_fold.compatCaselessMatch(allocator, a, b));
121
122 const c = "He\u{301}llo World! \u{3d2}\u{301}";
123 try expect(try case_fold.compatCaselessMatch(allocator, a, c));
124
125 // canonCaselessMatch isn't as comprehensive as compatCaselessMatch
126 // because it only decomposes and composes to NFC. But it's faster.
127 try expect(!try case_fold.canonCaselessMatch(allocator, a, b));
128 try expect(try case_fold.canonCaselessMatch(allocator, a, c));
129}
130
131const DisplayWidth = @import("DisplayWidth");
132
133test DisplayWidth {
134 const dw = try DisplayWidth.init(allocator);
135 defer dw.deinit(allocator);
136
137 // String display width
138 try expectEqual(@as(usize, 5), dw.strWidth("Hello\r\n"));
139 try expectEqual(@as(usize, 8), dw.strWidth("Hello 😊"));
140 try expectEqual(@as(usize, 8), dw.strWidth("Héllo 😊"));
141 try expectEqual(@as(usize, 9), dw.strWidth("Ẓ̌á̲l͔̝̞̄̑͌g̖̘̘̔̔͢͞͝o̪̔T̢̙̫̈̍͞e̬͈͕͌̏͑x̺̍ṭ̓̓ͅ"));
142 try expectEqual(@as(usize, 17), dw.strWidth("슬라바 우크라이나"));
143
144 // Centering text
145 const centered = try dw.center(allocator, "w😊w", 10, "-");
146 defer allocator.free(centered);
147 try expectEqualStrings("---w😊w---", centered);
148
149 // Pad left
150 const right_aligned = try dw.padLeft(allocator, "abc", 9, "*");
151 defer allocator.free(right_aligned);
152 try expectEqualStrings("******abc", right_aligned);
153
154 // Pad right
155 const left_aligned = try dw.padRight(allocator, "abc", 9, "*");
156 defer allocator.free(left_aligned);
157 try expectEqualStrings("abc******", left_aligned);
158
159 // Wrap text
160 const input = "The quick brown fox\r\njumped over the lazy dog!";
161 const wrapped = try dw.wrap(allocator, input, 10, 3);
162 defer allocator.free(wrapped);
163 const want =
164 \\The quick
165 \\brown fox
166 \\jumped
167 \\over the
168 \\lazy dog!
169 ;
170 try expectEqualStrings(want, wrapped);
171}
172
173const code_point = @import("code_point");
174
175test "Code point iterator" {
176 const str = "Hi 😊";
177 var iter = code_point.Iterator{ .bytes = str };
178 var i: usize = 0;
179
180 while (iter.next()) |cp| : (i += 1) {
181 if (i == 0) try expect(cp.code == 'H');
182 if (i == 1) try expect(cp.code == 'i');
183 if (i == 2) try expect(cp.code == ' ');
184
185 if (i == 3) {
186 try expect(cp.code == '😊');
187 try expect(cp.offset == 3);
188 try expect(cp.len == 4);
189 }
190 }
191}
192
193const Graphemes = @import("Graphemes");
194
195test "Grapheme cluster iterator" {
196 const graphemes = try Graphemes.init(allocator);
197 defer graphemes.deinit(allocator);
198 const str = "He\u{301}"; // Hé
199 var iter = graphemes.iterator(str);
200 var i: usize = 0;
201
202 while (iter.next()) |gc| : (i += 1) {
203 if (i == 0) try expect(gc.len == 1);
204
205 if (i == 1) {
206 try expect(gc.len == 3);
207 try expect(gc.offset == 1);
208 try expectEqualStrings("e\u{301}", gc.bytes(str));
209 }
210 }
211}
212
213const Scripts = @import("Scripts");
214
215test Scripts {
216 const scripts = try Scripts.init(allocator);
217 defer scripts.deinit(allocator);
218
219 try expect(scripts.script('A') == .Latin);
220 try expect(scripts.script('Ω') == .Greek);
221 try expect(scripts.script('צ') == .Hebrew);
222}
diff --git a/bench/src/zg_case.zig b/bench/src/zg_case.zig
deleted file mode 100644
index c444343..0000000
--- a/bench/src/zg_case.zig
+++ /dev/null
@@ -1,43 +0,0 @@
1const std = @import("std");
2
3const LetterCasing = @import("LetterCasing");
4
5pub fn main() !void {
6 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
7 defer arena.deinit();
8 const allocator = arena.allocator();
9
10 var args_iter = try std.process.argsWithAllocator(allocator);
11 _ = args_iter.skip();
12 const in_path = args_iter.next() orelse return error.MissingArg;
13
14 const input = try std.fs.cwd().readFileAlloc(
15 allocator,
16 in_path,
17 std.math.maxInt(u32),
18 );
19 defer allocator.free(input);
20
21 const case = try LetterCasing.init(allocator);
22
23 var iter = std.mem.splitScalar(u8, input, '\n');
24 var result: usize = 0;
25 var timer = try std.time.Timer.start();
26
27 while (iter.next()) |line| {
28 const upper = try case.toUpperStr(allocator, line);
29 const lower = try case.toLowerStr(allocator, line);
30 result += upper.len + lower.len;
31 }
32 std.debug.print("zg toUpperStr/toLowerStr: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
33
34 result = 0;
35 iter.reset();
36 timer.reset();
37
38 while (iter.next()) |line| {
39 if (case.isUpperStr(line)) result += 1;
40 if (case.isLowerStr(line)) result += 2;
41 }
42 std.debug.print("zg isUpperStr/isLowerStr: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
43}
diff --git a/bench/src/zg_caseless.zig b/bench/src/zg_caseless.zig
deleted file mode 100644
index 5d8d591..0000000
--- a/bench/src/zg_caseless.zig
+++ /dev/null
@@ -1,54 +0,0 @@
1const std = @import("std");
2
3const CaseFolding = @import("CaseFolding");
4
5pub fn main() !void {
6 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
7 defer arena.deinit();
8 const allocator = arena.allocator();
9
10 var args_iter = try std.process.argsWithAllocator(allocator);
11 _ = args_iter.skip();
12 const in_path = args_iter.next() orelse return error.MissingArg;
13
14 const input = try std.fs.cwd().readFileAlloc(
15 allocator,
16 in_path,
17 std.math.maxInt(u32),
18 );
19 defer allocator.free(input);
20
21 const case_fold = try CaseFolding.init(allocator);
22
23 var iter = std.mem.splitScalar(u8, input, '\n');
24 var result: usize = 0;
25 var buf: [256]u8 = [_]u8{'z'} ** 256;
26 var prev_line: []const u8 = buf[0..1];
27 var timer = try std.time.Timer.start();
28
29 while (iter.next()) |line| {
30 if (try case_fold.compatCaselessMatch(
31 allocator,
32 prev_line,
33 line,
34 )) result += 1;
35 @memcpy(buf[0..line.len], line);
36 prev_line = buf[0..line.len];
37 }
38 std.debug.print("zg CaseFolding.compatCaselessMatch: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
39
40 result = 0;
41 iter.reset();
42 timer.reset();
43
44 while (iter.next()) |line| {
45 if (try case_fold.canonCaselessMatch(
46 allocator,
47 prev_line,
48 line,
49 )) result += 1;
50 @memcpy(buf[0..line.len], line);
51 prev_line = buf[0..line.len];
52 }
53 std.debug.print("zg CaseFolding.canonCaselessMatch: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
54}
diff --git a/bench/src/zg_codepoint.zig b/bench/src/zg_codepoint.zig
deleted file mode 100644
index 2fe31f3..0000000
--- a/bench/src/zg_codepoint.zig
+++ /dev/null
@@ -1,27 +0,0 @@
1const std = @import("std");
2
3const code_point = @import("code_point");
4
5pub fn main() !void {
6 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
7 defer arena.deinit();
8 const allocator = arena.allocator();
9
10 var args_iter = try std.process.argsWithAllocator(allocator);
11 _ = args_iter.skip();
12 const in_path = args_iter.next() orelse return error.MissingArg;
13
14 const input = try std.fs.cwd().readFileAlloc(
15 allocator,
16 in_path,
17 std.math.maxInt(u32),
18 );
19 defer allocator.free(input);
20
21 var iter = code_point.Iterator{ .bytes = input };
22 var result: usize = 0;
23 var timer = try std.time.Timer.start();
24
25 while (iter.next()) |_| result += 1;
26 std.debug.print("zg CodePointIterator: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
27}
diff --git a/bench/src/zg_grapheme.zig b/bench/src/zg_grapheme.zig
deleted file mode 100644
index ee40de5..0000000
--- a/bench/src/zg_grapheme.zig
+++ /dev/null
@@ -1,28 +0,0 @@
1const std = @import("std");
2
3const Graphemes = @import("Graphemes");
4
5pub fn main() !void {
6 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
7 defer arena.deinit();
8 const allocator = arena.allocator();
9
10 var args_iter = try std.process.argsWithAllocator(allocator);
11 _ = args_iter.skip();
12 const in_path = args_iter.next() orelse return error.MissingArg;
13
14 const input = try std.fs.cwd().readFileAlloc(
15 allocator,
16 in_path,
17 std.math.maxInt(u32),
18 );
19 defer allocator.free(input);
20
21 const graphemes = try Graphemes.init(allocator);
22 var iter = graphemes.iterator(input);
23 var result: usize = 0;
24 var timer = try std.time.Timer.start();
25
26 while (iter.next()) |_| result += 1;
27 std.debug.print("zg Graphemes.Iterator: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
28}
diff --git a/bench/src/zg_normalize.zig b/bench/src/zg_normalize.zig
deleted file mode 100644
index 268c060..0000000
--- a/bench/src/zg_normalize.zig
+++ /dev/null
@@ -1,75 +0,0 @@
1const std = @import("std");
2
3const Normalize = @import("Normalize");
4
5pub fn main() !void {
6 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
7 defer arena.deinit();
8 const allocator = arena.allocator();
9
10 var args_iter = try std.process.argsWithAllocator(allocator);
11 _ = args_iter.skip();
12 const in_path = args_iter.next() orelse return error.MissingArg;
13
14 const input = try std.fs.cwd().readFileAlloc(
15 allocator,
16 in_path,
17 std.math.maxInt(u32),
18 );
19 defer allocator.free(input);
20
21 const normalize = try Normalize.init(allocator);
22
23 var iter = std.mem.splitScalar(u8, input, '\n');
24 var result: usize = 0;
25 var timer = try std.time.Timer.start();
26
27 while (iter.next()) |line| {
28 const nfkc = try normalize.nfkc(allocator, line);
29 result += nfkc.slice.len;
30 }
31 std.debug.print("zg Normalize.nfkc: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
32
33 result = 0;
34 iter.reset();
35 timer.reset();
36
37 while (iter.next()) |line| {
38 const nfc = try normalize.nfc(allocator, line);
39 result += nfc.slice.len;
40 }
41 std.debug.print("zg Normalize.nfc: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
42
43 result = 0;
44 iter.reset();
45 timer.reset();
46
47 while (iter.next()) |line| {
48 const nfkd = try normalize.nfkd(allocator, line);
49 result += nfkd.slice.len;
50 }
51 std.debug.print("zg Normalize.nfkd: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
52
53 result = 0;
54 iter.reset();
55 timer.reset();
56
57 while (iter.next()) |line| {
58 const nfd = try normalize.nfd(allocator, line);
59 result += nfd.slice.len;
60 }
61 std.debug.print("zg Normalize.nfd: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
62
63 result = 0;
64 iter.reset();
65 var buf: [256]u8 = [_]u8{'z'} ** 256;
66 var prev_line: []const u8 = buf[0..1];
67 timer.reset();
68
69 while (iter.next()) |line| {
70 if (try normalize.eql(allocator, prev_line, line)) result += 1;
71 @memcpy(buf[0..line.len], line);
72 prev_line = buf[0..line.len];
73 }
74 std.debug.print("Zg Normalize.eql: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
75}
diff --git a/bench/src/zg_width.zig b/bench/src/zg_width.zig
deleted file mode 100644
index b2db3fa..0000000
--- a/bench/src/zg_width.zig
+++ /dev/null
@@ -1,32 +0,0 @@
1const std = @import("std");
2
3const DisplayWidth = @import("DisplayWidth");
4
5pub fn main() !void {
6 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
7 defer arena.deinit();
8 const allocator = arena.allocator();
9
10 var args_iter = try std.process.argsWithAllocator(allocator);
11 _ = args_iter.skip();
12 const in_path = args_iter.next() orelse return error.MissingArg;
13
14 const input = try std.fs.cwd().readFileAlloc(
15 allocator,
16 in_path,
17 std.math.maxInt(u32),
18 );
19 defer allocator.free(input);
20
21 const display_width = try DisplayWidth.init(allocator);
22
23 var iter = std.mem.splitScalar(u8, input, '\n');
24 var result: usize = 0;
25 var timer = try std.time.Timer.start();
26
27 while (iter.next()) |line| {
28 const width = display_width.strWidth(line);
29 result += width;
30 }
31 std.debug.print("zg DisplayWidth.strWidth: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
32}
diff --git a/bench/src/ziglyph_case.zig b/bench/src/ziglyph_case.zig
deleted file mode 100644
index f6dfbc1..0000000
--- a/bench/src/ziglyph_case.zig
+++ /dev/null
@@ -1,41 +0,0 @@
1const std = @import("std");
2
3const ziglyph = @import("ziglyph");
4
5pub fn main() !void {
6 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
7 defer arena.deinit();
8 const allocator = arena.allocator();
9
10 var args_iter = try std.process.argsWithAllocator(allocator);
11 _ = args_iter.skip();
12 const in_path = args_iter.next() orelse return error.MissingArg;
13
14 const input = try std.fs.cwd().readFileAlloc(
15 allocator,
16 in_path,
17 std.math.maxInt(u32),
18 );
19 defer allocator.free(input);
20
21 var iter = std.mem.splitScalar(u8, input, '\n');
22 var result: usize = 0;
23 var timer = try std.time.Timer.start();
24
25 while (iter.next()) |line| {
26 const upper = try ziglyph.toUpperStr(allocator, line);
27 const lower = try ziglyph.toLowerStr(allocator, line);
28 result += upper.len + lower.len;
29 }
30 std.debug.print("Ziglyph toUpperStr/toLowerStr: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
31
32 result = 0;
33 iter.reset();
34 timer.reset();
35
36 while (iter.next()) |line| {
37 if (ziglyph.isUpperStr(line)) result += 1;
38 if (ziglyph.isLowerStr(line)) result += 2;
39 }
40 std.debug.print("Ziglyph isUpperStr/isLowerStr: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
41}
diff --git a/bench/src/ziglyph_caseless.zig b/bench/src/ziglyph_caseless.zig
deleted file mode 100644
index 4a22c22..0000000
--- a/bench/src/ziglyph_caseless.zig
+++ /dev/null
@@ -1,35 +0,0 @@
1const std = @import("std");
2
3const Normalizer = @import("ziglyph").Normalizer;
4
5pub fn main() !void {
6 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
7 defer arena.deinit();
8 const allocator = arena.allocator();
9
10 var args_iter = try std.process.argsWithAllocator(allocator);
11 _ = args_iter.skip();
12 const in_path = args_iter.next() orelse return error.MissingArg;
13
14 const input = try std.fs.cwd().readFileAlloc(
15 allocator,
16 in_path,
17 std.math.maxInt(u32),
18 );
19 defer allocator.free(input);
20
21 var normalizer = try Normalizer.init(allocator);
22
23 var iter = std.mem.splitScalar(u8, input, '\n');
24 var result: usize = 0;
25 var buf: [256]u8 = [_]u8{'z'} ** 256;
26 var prev_line: []const u8 = buf[0..1];
27 var timer = try std.time.Timer.start();
28
29 while (iter.next()) |line| {
30 if (try normalizer.eqlCaseless(allocator, prev_line, line)) result += 1;
31 @memcpy(buf[0..line.len], line);
32 prev_line = buf[0..line.len];
33 }
34 std.debug.print("Ziglyph Normalizer.eqlCaseless: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
35}
diff --git a/bench/src/ziglyph_codepoint.zig b/bench/src/ziglyph_codepoint.zig
deleted file mode 100644
index 7fe4028..0000000
--- a/bench/src/ziglyph_codepoint.zig
+++ /dev/null
@@ -1,27 +0,0 @@
1const std = @import("std");
2
3const CodePointIterator = @import("ziglyph").CodePointIterator;
4
5pub fn main() !void {
6 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
7 defer arena.deinit();
8 const allocator = arena.allocator();
9
10 var args_iter = try std.process.argsWithAllocator(allocator);
11 _ = args_iter.skip();
12 const in_path = args_iter.next() orelse return error.MissingArg;
13
14 const input = try std.fs.cwd().readFileAlloc(
15 allocator,
16 in_path,
17 std.math.maxInt(u32),
18 );
19 defer allocator.free(input);
20
21 var iter = CodePointIterator{ .bytes = input };
22 var result: usize = 0;
23 var timer = try std.time.Timer.start();
24
25 while (iter.next()) |_| result += 1;
26 std.debug.print("Ziglyph CodePointIterator: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
27}
diff --git a/bench/src/ziglyph_grapheme.zig b/bench/src/ziglyph_grapheme.zig
deleted file mode 100644
index 4fae2b0..0000000
--- a/bench/src/ziglyph_grapheme.zig
+++ /dev/null
@@ -1,27 +0,0 @@
1const std = @import("std");
2
3const GraphemeIterator = @import("ziglyph").GraphemeIterator;
4
5pub fn main() !void {
6 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
7 defer arena.deinit();
8 const allocator = arena.allocator();
9
10 var args_iter = try std.process.argsWithAllocator(allocator);
11 _ = args_iter.skip();
12 const in_path = args_iter.next() orelse return error.MissingArg;
13
14 const input = try std.fs.cwd().readFileAlloc(
15 allocator,
16 in_path,
17 std.math.maxInt(u32),
18 );
19 defer allocator.free(input);
20
21 var iter = GraphemeIterator.init(input);
22 var result: usize = 0;
23 var timer = try std.time.Timer.start();
24
25 while (iter.next()) |_| result += 1;
26 std.debug.print("Ziglyph GraphemeIterator: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
27}
diff --git a/bench/src/ziglyph_normalizer.zig b/bench/src/ziglyph_normalizer.zig
deleted file mode 100644
index e1e4c1b..0000000
--- a/bench/src/ziglyph_normalizer.zig
+++ /dev/null
@@ -1,75 +0,0 @@
1const std = @import("std");
2
3const Normalizer = @import("ziglyph").Normalizer;
4
5pub fn main() !void {
6 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
7 defer arena.deinit();
8 const allocator = arena.allocator();
9
10 var args_iter = try std.process.argsWithAllocator(allocator);
11 _ = args_iter.skip();
12 const in_path = args_iter.next() orelse return error.MissingArg;
13
14 const input = try std.fs.cwd().readFileAlloc(
15 allocator,
16 in_path,
17 std.math.maxInt(u32),
18 );
19 defer allocator.free(input);
20
21 var normalizer = try Normalizer.init(allocator);
22
23 var iter = std.mem.splitScalar(u8, input, '\n');
24 var result: usize = 0;
25 var timer = try std.time.Timer.start();
26
27 while (iter.next()) |line| {
28 const nfkc = try normalizer.nfkc(allocator, line);
29 result += nfkc.slice.len;
30 }
31 std.debug.print("Ziglyph Normalizer.nfkc: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
32
33 result = 0;
34 iter.reset();
35 timer.reset();
36
37 while (iter.next()) |line| {
38 const nfc = try normalizer.nfc(allocator, line);
39 result += nfc.slice.len;
40 }
41 std.debug.print("Ziglyph Normalizer.nfc: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
42
43 result = 0;
44 iter.reset();
45 timer.reset();
46
47 while (iter.next()) |line| {
48 const nfkd = try normalizer.nfkd(allocator, line);
49 result += nfkd.slice.len;
50 }
51 std.debug.print("Ziglyph Normalizer.nfkd: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
52
53 result = 0;
54 iter.reset();
55 timer.reset();
56
57 while (iter.next()) |line| {
58 const nfd = try normalizer.nfd(allocator, line);
59 result += nfd.slice.len;
60 }
61 std.debug.print("Ziglyph Normalizer.nfd: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
62
63 result = 0;
64 iter.reset();
65 var buf: [256]u8 = [_]u8{'z'} ** 256;
66 var prev_line: []const u8 = buf[0..1];
67 timer.reset();
68
69 while (iter.next()) |line| {
70 if (try normalizer.eql(allocator, prev_line, line)) result += 1;
71 @memcpy(buf[0..line.len], line);
72 prev_line = buf[0..line.len];
73 }
74 std.debug.print("Ziglyph Normalizer.eql: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
75}
diff --git a/bench/src/ziglyph_width.zig b/bench/src/ziglyph_width.zig
deleted file mode 100644
index 590ac3e..0000000
--- a/bench/src/ziglyph_width.zig
+++ /dev/null
@@ -1,30 +0,0 @@
1const std = @import("std");
2
3const display_width = @import("ziglyph").display_width;
4
5pub fn main() !void {
6 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
7 defer arena.deinit();
8 const allocator = arena.allocator();
9
10 var args_iter = try std.process.argsWithAllocator(allocator);
11 _ = args_iter.skip();
12 const in_path = args_iter.next() orelse return error.MissingArg;
13
14 const input = try std.fs.cwd().readFileAlloc(
15 allocator,
16 in_path,
17 std.math.maxInt(u32),
18 );
19 defer allocator.free(input);
20
21 var iter = std.mem.splitScalar(u8, input, '\n');
22 var result: usize = 0;
23 var timer = try std.time.Timer.start();
24
25 while (iter.next()) |line| {
26 const width = try display_width.strWidth(line, .half);
27 result += width;
28 }
29 std.debug.print("Ziglyph display_width.strWidth: result: {}, took: {}\n", .{ result, std.fmt.fmtDuration(timer.lap()) });
30}