From 4feb810d934221da2ea3f7f2251ba3de0d754617 Mon Sep 17 00:00:00 2001 From: Kalle Carlbark Date: Thu, 24 Oct 2024 21:03:45 +0200 Subject: [PATCH] wip: zbench --- build.zig.zon | 2 +- src/main.zig | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index 3d34a20..fa0149a 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -10,7 +10,7 @@ }, .zbench = .{ .url = "https://github.com/hendriknielaender/zbench/archive/0.13.0/latest.tar.gz", - .hash = "1220fe24b0832ac690c1999d321ee1a220e738db71bf46c7e3a8947139a384f8d51d", + .hash = "1220b7219ed9b700aaac2a5f84af3c2b3a7c8f714f701511912434525f41735f950b", }, }, } diff --git a/src/main.zig b/src/main.zig index cdeb5b1..b6fbc1c 100644 --- a/src/main.zig +++ b/src/main.zig @@ -8,6 +8,7 @@ const zbench = @import("zbench"); pub fn main() !void { const params = comptime clap.parseParamsComptime( + \\-b, --benchmark Benchmark \\-h, --help Display this help and exit. \\-d, --decode Decode base64 to string. \\-e, --encode Encode string to base64. @@ -33,9 +34,17 @@ pub fn main() !void { const stdout = std.io.getStdOut(); + if (res.args.benchmark != 0) { + var bench = zbench.Benchmark.init(allocator, .{}); + defer bench.deinit(); + + try bench.add("decode", bench_decode, .{}); + try bench.run(io.getStdOut().writer()); + } + if (res.args.help != 0) { usage(); - try clap.help(std.io.getStdErr().writer(), clap.Help, ¶ms, .{}); + try clap.help(io.getStdErr().writer(), clap.Help, ¶ms, .{}); return; } @@ -166,7 +175,7 @@ fn decode(allocator: std.mem.Allocator, b64string: []const u8) ![]u8 { fn bench_decode(allocator: std.mem.Allocator) void { const base64String = "aGVqIGxrc2pkbGthanNkIGxha3NqZGxramFzZA=="; - _ = try decode(allocator, base64String); + try decode(allocator, base64String); } test "bench decode" {