summaryrefslogtreecommitdiff
path: root/bench/src/zg_normalize.zig
diff options
context:
space:
mode:
Diffstat (limited to 'bench/src/zg_normalize.zig')
-rw-r--r--bench/src/zg_normalize.zig76
1 files changed, 76 insertions, 0 deletions
diff --git a/bench/src/zg_normalize.zig b/bench/src/zg_normalize.zig
new file mode 100644
index 0000000..956106f
--- /dev/null
+++ b/bench/src/zg_normalize.zig
@@ -0,0 +1,76 @@
1const std = @import("std");
2
3const Normalize = @import("Normalize");
4
5pub fn main() !void {
6 var args_iter = std.process.args();
7 _ = args_iter.skip();
8 const in_path = args_iter.next() orelse return error.MissingArg;
9
10 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
11 defer arena.deinit();
12 const allocator = arena.allocator();
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 norm_data = try Normalize.NormData.init(allocator);
22 const normalize = Normalize{ .norm_data = &norm_data };
23
24 var iter = std.mem.splitScalar(u8, input, '\n');
25 var result: usize = 0;
26 var timer = try std.time.Timer.start();
27
28 while (iter.next()) |line| {
29 const nfkc = try normalize.nfkc(allocator, line);
30 result += nfkc.slice.len;
31 }
32 std.debug.print("zg Normalize.nfkc: result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms });
33
34 result = 0;
35 iter.reset();
36 timer.reset();
37
38 while (iter.next()) |line| {
39 const nfc = try normalize.nfc(allocator, line);
40 result += nfc.slice.len;
41 }
42 std.debug.print("zg Normalize.nfc: result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms });
43
44 result = 0;
45 iter.reset();
46 timer.reset();
47
48 while (iter.next()) |line| {
49 const nfkd = try normalize.nfkd(allocator, line);
50 result += nfkd.slice.len;
51 }
52 std.debug.print("zg Normalize.nfkd: result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms });
53
54 result = 0;
55 iter.reset();
56 timer.reset();
57
58 while (iter.next()) |line| {
59 const nfd = try normalize.nfd(allocator, line);
60 result += nfd.slice.len;
61 }
62 std.debug.print("zg Normalize.nfd: result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms });
63
64 result = 0;
65 iter.reset();
66 var buf: [256]u8 = [_]u8{'z'} ** 256;
67 var prev_line: []const u8 = buf[0..1];
68 timer.reset();
69
70 while (iter.next()) |line| {
71 if (try normalize.eql(allocator, prev_line, line)) result += 1;
72 @memcpy(buf[0..line.len], line);
73 prev_line = buf[0..line.len];
74 }
75 std.debug.print("Zg Normalize.eql: result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms });
76}