Examples covering the main usage patterns:
- bench_append_u8: per-iteration heap work, demonstrates B/op tracking
via the wrapped allocator.
- bench_sha256_64: set_bytes() for throughput in MB/s.
- bench_integer_sum: shows the optimization pitfall with a comment —
trivial loop bodies need an in-loop b.keep to survive ReleaseFast.
- bench_hash_sizes: parent that delegates to sub-benchmarks via b.run,
printed as `hash_sizes/sha256_<size>`.
- memset_{16,256,4096}: comptime-parametric benchmark generation via
std.fmt.comptimePrint + a generic gen_bench factory.
Includes a stand-alone examples/bench/build.zig illustrating the
zbench_build.add_bench_step integration a downstream project would use.
27 lines
880 B
Zig
27 lines
880 B
Zig
//! Stand-alone build for the example, illustrating how a downstream project
|
|
//! wires up `zig build bench` using the `zbench_build` helper.
|
|
//!
|
|
//! Note: when building the example from the zbench repo root via
|
|
//! `zig build example`, this file is unused — the root `build.zig` wires
|
|
//! it up directly. This file demonstrates the integration pattern for a
|
|
//! consumer project that lists `zbench` as a dependency.
|
|
|
|
const std = @import("std");
|
|
const zbench_build = @import("zbench_build");
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const target = b.standardTargetOptions(.{});
|
|
|
|
const zbench = b.dependency("zbench", .{
|
|
.target = target,
|
|
.optimize = .ReleaseFast,
|
|
});
|
|
|
|
_ = zbench_build.add_bench_step(b, .{
|
|
.step_name = "bench",
|
|
.root = b.path("main.zig"),
|
|
.target = target,
|
|
.zbench = zbench.module("zbench"),
|
|
});
|
|
}
|