Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Add timings
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn committed Mar 1, 2024
1 parent 65d47c6 commit d6b62ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Supported Codecs:

Requires Zig trunk >= 0.12.0-dev.2541

Benchmarks can be run with `zig build bench`
Benchmarks can be run with `zig build bench -Doptimize=ReleaseSafe`

## What is FastLanes?

Expand Down
7 changes: 6 additions & 1 deletion src/bench.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@ pub fn Bench(comptime name: []const u8, comptime variant: []const u8, comptime o
unit.run();
}

var timer = try std.time.Timer.start();
const start = cycleclock.now();
for (0..options.iterations) |_| {
unit.run();
}
const stop = cycleclock.now();
const elapsed_ns = timer.read();
const cycles = stop - start;

const billion_tuples_per_second = 1024.0 * @as(f64, @floatFromInt(options.iterations)) / @as(f64, @floatFromInt(elapsed_ns));
std.debug.print(",{d:.2}", .{billion_tuples_per_second});

if (cycles == 0) {
std.debug.print(",0 # failed to measure cycles\n", .{});
std.debug.print(",0.0,0 # failed to measure cycles\n", .{});
return;
} else {
const cycles_per_tuple = @as(f64, @floatFromInt(cycles)) / @as(f64, @floatFromInt(1024 * options.iterations));
Expand Down

0 comments on commit d6b62ab

Please sign in to comment.