-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the same problem in the std.Progress branch
Also added a test example for memory tracking to compare overhead.
- Loading branch information
Showing
3 changed files
with
28 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const std = @import("std"); | ||
const zbench = @import("zbench"); | ||
|
||
fn myBenchmark(allocator: std.mem.Allocator) void { | ||
for (0..2000) |_| { | ||
const buf = allocator.alloc(u8, 512) catch @panic("OOM"); | ||
defer allocator.free(buf); | ||
} | ||
} | ||
|
||
test "bench test basic" { | ||
const stdout = std.io.getStdOut().writer(); | ||
var bench = zbench.Benchmark.init(std.testing.allocator, .{ | ||
.iterations = 64, | ||
}); | ||
defer bench.deinit(); | ||
|
||
try bench.add("My Benchmark 1", myBenchmark, .{}); | ||
try bench.add("My Benchmark 2", myBenchmark, .{ | ||
.track_allocations = true, | ||
}); | ||
|
||
try stdout.writeAll("\n"); | ||
try bench.run(stdout); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters