package thumper
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=ccf45c4d2bfd6444270c51317e2b83e531d8e4bdc09d5bdb1d0069cd7fe2e43d
sha512=68510d10a959bb89e0a03b48b136f65b31904dfcbc37f2ecd2c8b58f0dd852b6aed5d03fc659c952ca5745762b35ce6042ef147f63360db4270d6da6a20589cc
doc/README.html
Thumper — benchmark regression tests for OCaml
Thumper measures OCaml benchmarks and checks them against a committed baseline, so a dune rule fails the build on a confirmed regression. A benchmark is an executable that a project keeps beside its code and runs under dune, on a developer's machine or in CI. Thumper requires OCaml 5.2 or later, depends on the unix library alone, measures on Unix, and is distributed under the ISC license.
Quick start
A benchmark is a program that ends in Thumper.run. The two files of examples/01-first-benchmark, in a project's bench/ directory, make one with a single case.
examples/01-first-benchmark/bench_hello.ml:
let input = List.init 1_000 Fun.id
let () =
exit
(Thumper.run "hello"
[ Thumper.bench "list-rev" (fun () -> List.rev input) ])examples/01-first-benchmark/dune:
(executable
(name bench_hello)
(libraries thumper))With no baseline yet, the first run measures the case, proposes it and names the command that records it (the numbers are one run's):
$ dune exec bench/bench_hello.exe
hello: no baseline for machine 943935ae6b4f79ac (Apple M1 Max)
proposed 1.35 us ±1.3% 3,000 w list-rev
accept: ./_build/default/bench/bench_hello.exe bless
1 proposed in 243ms.Running the accept: line writes bench/hello.thumper, which the project commits, and every later run checks against it. Getting started runs a suite from a dune rule, records its baseline, and makes the check fail.
Features
- Benchmarks declared with
bench,bench_with_setupandgroup, and a command line fromThumper.run:check(the default),blessandlist. - A baseline file per suite, committed beside the benchmark's source, that stores what was measured (sorted samples and exact counts) in one section per machine.
checkjudges and writes no baseline;blessalone records one, and the report'saccept:line names theblesscommand for its proposed and improved cases.- A dune rule per suite on the
@benchalias, which depends on its baseline through(deps (glob_files *.thumper))and fails the build when a case fails. - Budgets per metric: a bound on the change from the baseline (
no_slower_than,no_more_alloc_than) or on the measured value (at_most). Every collected metric has one, 5% by default. - Rank statistics with an in-run confirmation: a timing regression or improvement counts only when a second trial of the case reproduces it, and a change whose interval ends within its budget passes.
- Exact allocation counts: when a probe proves that a case allocates the same number of words on every call, the count compares as an integer. The count is the same on every CPU and under any load, so a suite that collects it alone can be checked on hosted CI runners.
- Each case measured in its own forked process, within a deadline, at the batch size its baseline recorded while one batch still takes 0.2 to 5 times the batch floor.
- Timing comparisons on a loaded host reported as
inconclusive: environmentinstead of failing,--wait-quietto wait for a quiet host, and ablessthat refuses a loaded host. - A per-user lock that serializes measurement between processes on a host.
--jsonfor a JSON document of the verdict,--strictto fail a metric with no baseline row, and GitHub annotations underGITHUB_ACTIONS.- The same machinery as a library:
measurecollects measurements without files, andCheck.run,Baseline.recordandVerdict.to_jsonbuild a check in OCaml.
Installation
opam install thumperDocumentation
The manual, doc/manual/, has one page per need:
- Tutorial: Getting started, a benchmark from its first run to a failing check.
How-to:
- Writing benchmarks: budgets, fixtures, families of cases, tags, metrics and the protocol.
- Running checks: one case while iterating, recording a baseline, several machines, CI and loaded hosts.
- Programmatic use: measuring and checking from an OCaml program.
Reference:
- Command line: the help, the subcommands and case selection.
- The report: every line
checkandblessprint, and what to do about an inconclusive row. - The JSON document: every field
--jsonwrites. - The baseline format: the grammar of a
.thumperfile. - The API:
lib/thumper.mli, also read withodig doc thumper.
- Explanation: How checks decide, why a check reads each row as it does.
Questions are welcome on the OCaml forum.
Examples
examples/ holds seven suites, from a first benchmark to the library without the command line; its README lists them.
Contributing
doc/dev/ records thumper's architecture, its statistics and how it tests itself.