summaryrefslogtreecommitdiff
path: root/bench/src/ziglyph_caseless.zig
diff options
context:
space:
mode:
Diffstat (limited to 'bench/src/ziglyph_caseless.zig')
-rw-r--r--bench/src/ziglyph_caseless.zig35
1 files changed, 35 insertions, 0 deletions
diff --git a/bench/src/ziglyph_caseless.zig b/bench/src/ziglyph_caseless.zig
new file mode 100644
index 0000000..f80668e
--- /dev/null
+++ b/bench/src/ziglyph_caseless.zig
@@ -0,0 +1,35 @@
1const std = @import("std");
2
3const Normalizer = @import("ziglyph").Normalizer;
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 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, timer.lap() / std.time.ns_per_ms });
35}