Skip to content
Small and easy micro-benchmarking library.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
README.md
bench.zig

README.md

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);
}
You can’t perform that action at this time.