diff options
| author | 2025-07-08 12:15:32 -0400 | |
|---|---|---|
| committer | 2025-07-08 12:15:32 -0400 | |
| commit | 9427a9e53aaa29ee071f4dcb35b809a699d75aa9 (patch) | |
| tree | 2607c185fd8053b84d60041fadc35c05a0225d34 /bench/src/ziglyph_case.zig | |
| parent | Merge pull request 'Fix benchmarks' (#56) from jacobsandlund/zg:benchmarks in... (diff) | |
| parent | Add Words.zig example to README (diff) | |
| download | zg-master.tar.gz zg-master.tar.xz zg-master.zip | |
Diffstat (limited to 'bench/src/ziglyph_case.zig')
| -rw-r--r-- | bench/src/ziglyph_case.zig | 41 |
1 files changed, 0 insertions, 41 deletions
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 @@ | |||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | const ziglyph = @import("ziglyph"); | ||
| 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 | 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 | } | ||