Skip to content

Commit 54ea53b

Browse files
authored
refactor(root): introduce Metrics, perf, Runner and Reporter (#15)
1 parent e5e21fb commit 54ea53b

10 files changed

Lines changed: 933 additions & 721 deletions

File tree

src/Metrics.zig

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// Meta
3+
4+
/// The identifier string for the benchmark
5+
name: []const u8,
6+
/// Total number of measurement samples collected
7+
samples: usize,
8+
9+
///////////////////////////////////////////////////////////////////////////////
10+
// Time
11+
12+
/// Minimum execution time per operation (nanoseconds)
13+
min_ns: f64,
14+
/// Maximum execution time per operation (nanoseconds)
15+
max_ns: f64,
16+
/// Mean execution time (nanoseconds)
17+
mean_ns: f64,
18+
/// Median execution time (nanoseconds)
19+
median_ns: f64,
20+
/// Standard deviation of the execution time
21+
std_dev_ns: f64,
22+
23+
///////////////////////////////////////////////////////////////////////////////
24+
// Throughput
25+
26+
/// Calculated operations per second
27+
ops_sec: f64,
28+
/// Data throughput in MB/s (populated if `bytes_per_op` > 0)
29+
mb_sec: f64,
30+
31+
///////////////////////////////////////////////////////////////////////////////
32+
// Hardware (Linux only, null otherwise)
33+
34+
/// Average CPU cycles per operation
35+
cycles: ?f64 = null,
36+
/// Average CPU instructions executed per operation
37+
instructions: ?f64 = null,
38+
/// Instructions Per Cycle (efficiency ratio)
39+
ipc: ?f64 = null,
40+
/// Average cache misses per operation
41+
cache_misses: ?f64 = null,

src/Perf.test.zig

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/Perf.zig

Lines changed: 0 additions & 152 deletions
This file was deleted.

src/Reporter.test.zig

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const std = @import("std");
2+
const testing = std.testing;
3+
4+
const Runner = @import("Runner.zig");
5+
const Reporter = @import("Reporter.zig");
6+
7+
fn fibNaive(n: u64) u64 {
8+
if (n <= 1) return n;
9+
return fibNaive(n - 1) + fibNaive(n - 2);
10+
}
11+
12+
fn fibIterative(n: u64) u64 {
13+
if (n == 0) return 0;
14+
var a: u64 = 0;
15+
var b: u64 = 1;
16+
for (2..n + 1) |_| {
17+
const c = a + b;
18+
a = b;
19+
b = c;
20+
}
21+
return b;
22+
}
23+
24+
test "report fib" {
25+
const allocator = testing.allocator;
26+
const opts = Runner.Options{
27+
.sample_size = 100,
28+
.warmup_iters = 3,
29+
};
30+
const m_naive = try Runner.run(allocator, "fibNaive", fibNaive, .{@as(u64, 20)}, opts);
31+
const m_iter = try Runner.run(allocator, "fibIterative", fibIterative, .{@as(u64, 20)}, opts);
32+
33+
try Reporter.report(.{ .metrics = &.{ m_naive, m_iter }, .baseline_index = 0 });
34+
}

0 commit comments

Comments
 (0)