blob: 6e21df09990d8ab9b1a6f4225cb35943fa982a50 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
const std = @import("std");
const Ts = std.Io.Timestamp;
fn benchmark(name: []const u8, iters: usize, func: fn () anyerror!void) !void {
const io = std.Io.Threaded.global_single_threaded.io();
const clock = std.Io.Clock.cpu_thread;
const start = clock.now(io);
for (0..iters) |i| {
_ = i;
try func();
}
const stop = clock.now(io);
const ns: f64 = @floatFromInt(start.durationTo(stop).nanoseconds);
const secs = ns / 1_000_000_000;
std.debug.print(
"bench {s} x {}: {d:.3}s\n",
.{ name, iters, secs },
);
}
|