Skip to content
odinbenchmarkingperformancecli

obench

Micro-benchmarking for Odin that counts allocations: time and heap and temp allocations per operation, @zero_alloc checks, a saved baseline to compare against, and odin test integration.

since October 20262Odinpushed 7 days ago

obench

obench is a micro-benchmarking library and CLI for Odin. For every operation it measures the time and the heap and temp allocations, and it compares a run against a saved baseline, so a pull request can be held back when it gets slower. It uses only Odin's base: and core: packages.

Install

obench needs Odin dev-2026-10 or newer. Copy the obench folder of the repository into your project, for example as libs/obench. Every release has it as a .tar.gz and a .zip too. Then build the CLI from a clone:

mkdir -p bin
odin build cmd/obench -out:bin/obench -o:speed

Or take a prebuilt one from a release. It still needs odin on your PATH.

A benchmark

A benchmark is a procedure named bench_<name> that takes a ^obench.Bencher, and only the body of the step loop is timed and counted:

package append_bench
 
import obench "../libs/obench"
 
// @params(16, 256, 4096)
bench_append__grow :: proc(b: ^obench.Bencher) {
	n := obench.param(b)
	for obench.step(b) {
		values: [dynamic]int
		for i in 0 ..< n {
			append(&values, i)
		}
		obench.keep_alive(&values)
		delete(values)
	}
}
 
// @params(16, 256, 4096)
bench_append__reserve :: proc(b: ^obench.Bencher) {
	n := obench.param(b)
	for obench.step(b) {
		values := make([dynamic]int, 0, n)
		for i in 0 ..< n {
			append(&values, i)
		}
		obench.keep_alive(&values)
		delete(values)
	}
}

./bin/obench path/to/project runs them. On an Apple M2:

obench: append_bench (darwin/arm64, -o:Speed, timer overhead 28.5 ns, resolution 41.0 ns)
──────────────────────────────────────────────────────────────────────────────────────────────────
benchmark         │   fastest │ median(p50) │       p99 │   allocs / bytes │ distribution & notes
──────────────────────────────────────────────────────────────────────────────────────────────────
append
 ├─ grow[16]      │  77.41 ns │    78.29 ns │  82.36 ns │      2.0 / 128 B │ █▆▁▂ ▂▂▁
 ├─ reserve[16]   │  35.49 ns │    38.04 ns │  43.22 ns │      1.0 / 128 B │ ▅█▅▄▄▃▁▁ 2.06x faster
 ├─ grow[256]     │ 540.42 ns │   545.34 ns │ 579.68 ns │   6.0 / 2.00 KiB │ █▂▂▁▁  ▁
 ├─ reserve[256]  │ 232.38 ns │   239.52 ns │ 305.09 ns │   1.0 / 2.00 KiB │ █▃▁▁   ▁ 2.28x faster
 ├─ grow[4096]    │   4.68 us │     4.80 us │   5.42 us │ 10.0 / 32.00 KiB │ ██▂▂▁▁▁▁
 ╰─ reserve[4096] │   3.32 us │     3.39 us │   3.54 us │  1.0 / 32.00 KiB │ █▂▄▃▂▁▁▂ 1.42x faster
   ∷ complexity grow    → O(N) (R²=0.999, NRMSE=4.4%)
   ∷ complexity reserve → O(N) (R²=1.000, NRMSE=0.2%)
──────────────────────────────────────────────────────────────────────────────────────────────────
PASS: 6 benchmark(s) completed │ geomean: 430.06 ns

Reserving up front makes one allocation where growing makes two, six or ten, and it's 1.42 to 2.28 times faster. olint checks the same @zero_alloc annotation without running anything.

obench is before 1.0, so the API and the JSON report can still change, and the release notes list every breaking change. CI tests it on Linux, macOS and Windows. It's under the BSD-3-Clause licence.

latest on main

  1. c1dd6d2chore(main): release 0.5.0 (#112)7 days ago
  2. 95402a4test: give the timing checks room on a busy runner (#120)7 days ago
  3. 9b7d81bfix!: refuse the flags --instructions can't honor (#116)7 days ago
  4. b834202docs!: name the stable part of the package in STABILITY.md (#118)7 days ago
  5. 9c56e67fix: calibrate the clock after each warmup, with the median of the block means (#114)7 days ago
  6. 7f4fed4feat: warn when only one side of a comparison comes from several processes (#117)7 days ago
  7. all commits →