No description
Find a file
2021-06-28 08:50:48 -04:00
.gitignore add gyro package file. 2021-06-28 08:50:48 -04:00
bench.zig fix timer depending on run length which caused it to run longer for shorter functions. 2021-06-28 08:39:53 -04:00
gyro.zzz add gyro package file. 2021-06-28 08:50:48 -04:00
README.md add readme 2019-04-16 23:58:27 +02:00

Goal

zig-benchmark provides a minimal API to do micro-benchmarking.

Everything it contains is very barebones compared to mature benchmarking frameworks, but usable nonetheless.

Features

  • easy to use
  • runs every micro-benchmark in fixed time
  • pre-warming, to get the caches ready
  • ugly text report

Example

Simple

const bench = @import("bench.zig");

fn longCompute(ctx: *bench.Context) void {
    while (ctx.run()) {
        // something you want to time
    }
}

pub fn main() void {
    bench.benchmark("longCompute", longCompute);
}

With arguments

const bench = @import("bench.zig");

fn longCompute(ctx: *bench.Context, x: u32) void {
    while (ctx.run()) {
        // something you want to time
    }
}

pub fn main() void {
    bench.benchmarkArgs("longCompute", longCompute, []const u32{ 1, 2, 3, 4 });
}

Works with types as arguments, too.

With explicit timing

const bench = @import("bench.zig");

fn longCompute(ctx: *bench.Context) void {
    while (ctx.runExplicitTiming()) {
        // do some set-up

        ctx.startTimer();
        // something you want to time
        ctx.stopTimer();
    }
}

pub fn main() void {
    bench.benchmark("longCompute", longCompute);
}