package thumper

All checked builds pass
  1. Overview
  2. Docs
Micro-benchmarks as regression tests for OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

thumper-0.1.0.tbz
sha256=ccf45c4d2bfd6444270c51317e2b83e531d8e4bdc09d5bdb1d0069cd7fe2e43d
sha512=68510d10a959bb89e0a03b48b136f65b31904dfcbc37f2ecd2c8b58f0dd852b6aed5d03fc659c952ca5745762b35ce6042ef147f63360db4270d6da6a20589cc

Description

Thumper measures OCaml micro-benchmarks and checks them against a committed baseline, so a dune rule fails the build when a case regresses beyond its budget. The baseline stores the evidence, sorted timing samples and exact allocation counts, in one section per machine. A timing comparison is a rank test, and a regression or improvement stands only when a confirmation pass in the same run reproduces it; an exact count compares as an integer. A comparison that cannot decide is inconclusive and fails nothing. A case with no baseline row yet is proposed and passes, and fails only under --strict; bless records the baseline. Thumper depends on the unix library alone. On Unix each case runs in a forked worker.

Added to opam-repository:

README

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_setup and group, and a command line from Thumper.run: check (the default), bless and list.
  • 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.
  • check judges and writes no baseline; bless alone records one, and the report's accept: line names the bless command for its proposed and improved cases.
  • A dune rule per suite on the @bench alias, 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: environment instead of failing, --wait-quiet to wait for a quiet host, and a bless that refuses a loaded host.
  • A per-user lock that serializes measurement between processes on a host.
  • --json for a JSON document of the verdict, --strict to fail a metric with no baseline row, and GitHub annotations under GITHUB_ACTIONS.
  • The same machinery as a library: measure collects measurements without files, and Check.run, Baseline.record and Verdict.to_json build a check in OCaml.

Installation

opam install thumper

Documentation

The manual, doc/manual/, has one page per need:

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.

Dependencies (2)

  1. ocaml >= "5.2"
  2. dune >= "3.21"

Dev Dependencies (2)

  1. odoc with-doc
  2. windtrap with-test & >= "0.3.0"

Optional Dependencies

None

Used by (3)

  1. matrix >= "0.2.0"
  2. mosaic >= "0.2.0"
  3. toffee >= "0.2.0"

Conflicts

None

Build status

Results of building thumper with each compiler on check.ci.ocaml.org, run of against opam-repository 8d8d144. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
0.1.0 (this version) n/a n/a good good good
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure