Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/Metrics.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
///////////////////////////////////////////////////////////////////////////////
// Meta

/// The identifier string for the benchmark
name: []const u8,
/// Total number of measurement samples collected
samples: usize,

///////////////////////////////////////////////////////////////////////////////
// Time

/// Minimum execution time per operation (nanoseconds)
min_ns: f64,
/// Maximum execution time per operation (nanoseconds)
max_ns: f64,
/// Mean execution time (nanoseconds)
mean_ns: f64,
/// Median execution time (nanoseconds)
median_ns: f64,
/// Standard deviation of the execution time
std_dev_ns: f64,

///////////////////////////////////////////////////////////////////////////////
// Throughput

/// Calculated operations per second
ops_sec: f64,
/// Data throughput in MB/s (populated if `bytes_per_op` > 0)
mb_sec: f64,

///////////////////////////////////////////////////////////////////////////////
// Hardware (Linux only, null otherwise)

/// Average CPU cycles per operation
cycles: ?f64 = null,
/// Average CPU instructions executed per operation
instructions: ?f64 = null,
/// Instructions Per Cycle (efficiency ratio)
ipc: ?f64 = null,
/// Average cache misses per operation
cache_misses: ?f64 = null,
51 changes: 0 additions & 51 deletions src/Perf.test.zig

This file was deleted.

152 changes: 0 additions & 152 deletions src/Perf.zig

This file was deleted.

34 changes: 34 additions & 0 deletions src/Reporter.test.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const std = @import("std");
const testing = std.testing;

const Runner = @import("Runner.zig");
const Reporter = @import("Reporter.zig");

fn fibNaive(n: u64) u64 {
if (n <= 1) return n;
return fibNaive(n - 1) + fibNaive(n - 2);
}

fn fibIterative(n: u64) u64 {
if (n == 0) return 0;
var a: u64 = 0;
var b: u64 = 1;
for (2..n + 1) |_| {
const c = a + b;
a = b;
b = c;
}
return b;
}

test "report fib" {
const allocator = testing.allocator;
const opts = Runner.Options{
.sample_size = 100,
.warmup_iters = 3,
};
const m_naive = try Runner.run(allocator, "fibNaive", fibNaive, .{@as(u64, 20)}, opts);
const m_iter = try Runner.run(allocator, "fibIterative", fibIterative, .{@as(u64, 20)}, opts);

try Reporter.report(.{ .metrics = &.{ m_naive, m_iter }, .baseline_index = 0 });
}
Loading