wip: zbench
This commit is contained in:
parent
8484063764
commit
4feb810d93
2 changed files with 12 additions and 3 deletions
|
@ -10,7 +10,7 @@
|
|||
},
|
||||
.zbench = .{
|
||||
.url = "https://github.com/hendriknielaender/zbench/archive/0.13.0/latest.tar.gz",
|
||||
.hash = "1220fe24b0832ac690c1999d321ee1a220e738db71bf46c7e3a8947139a384f8d51d",
|
||||
.hash = "1220b7219ed9b700aaac2a5f84af3c2b3a7c8f714f701511912434525f41735f950b",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
13
src/main.zig
13
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" {
|
||||
|
|
Loading…
Reference in a new issue