wip: zbench

This commit is contained in:
Kalle Carlbark 2024-10-24 21:03:45 +02:00
parent 8484063764
commit 4feb810d93
No known key found for this signature in database
2 changed files with 12 additions and 3 deletions

View file

@ -10,7 +10,7 @@
}, },
.zbench = .{ .zbench = .{
.url = "https://github.com/hendriknielaender/zbench/archive/0.13.0/latest.tar.gz", .url = "https://github.com/hendriknielaender/zbench/archive/0.13.0/latest.tar.gz",
.hash = "1220fe24b0832ac690c1999d321ee1a220e738db71bf46c7e3a8947139a384f8d51d", .hash = "1220b7219ed9b700aaac2a5f84af3c2b3a7c8f714f701511912434525f41735f950b",
}, },
}, },
} }

View file

@ -8,6 +8,7 @@ const zbench = @import("zbench");
pub fn main() !void { pub fn main() !void {
const params = comptime clap.parseParamsComptime( const params = comptime clap.parseParamsComptime(
\\-b, --benchmark Benchmark
\\-h, --help Display this help and exit. \\-h, --help Display this help and exit.
\\-d, --decode Decode base64 to string. \\-d, --decode Decode base64 to string.
\\-e, --encode Encode string to base64. \\-e, --encode Encode string to base64.
@ -33,9 +34,17 @@ pub fn main() !void {
const stdout = std.io.getStdOut(); 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) { if (res.args.help != 0) {
usage(); usage();
try clap.help(std.io.getStdErr().writer(), clap.Help, &params, .{}); try clap.help(io.getStdErr().writer(), clap.Help, &params, .{});
return; return;
} }
@ -166,7 +175,7 @@ fn decode(allocator: std.mem.Allocator, b64string: []const u8) ![]u8 {
fn bench_decode(allocator: std.mem.Allocator) void { fn bench_decode(allocator: std.mem.Allocator) void {
const base64String = "aGVqIGxrc2pkbGthanNkIGxha3NqZGxramFzZA=="; const base64String = "aGVqIGxrc2pkbGthanNkIGxha3NqZGxramFzZA==";
_ = try decode(allocator, base64String); try decode(allocator, base64String);
} }
test "bench decode" { test "bench decode" {