Skip to content

Small and easy micro-benchmarking library.

Notifications You must be signed in to change notification settings

balenamiaa/zig-benchmark

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

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);
}

About

Small and easy micro-benchmarking library.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Zig 100.0%