diff options
Diffstat (limited to 'bench/src/zg_normalize.zig')
| -rw-r--r-- | bench/src/zg_normalize.zig | 75 |
1 files changed, 0 insertions, 75 deletions
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 @@ | |||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | const Normalize = @import("Normalize"); | ||
| 4 | |||
| 5 | pub 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 | } | ||