Maintenance status: I no longer actively maintain this software. Expect details here to be outdated.
criterion
helps you write reliable microbenchmarks without becoming a benchmarking expert.
It automates the noisy details, so you can focus on understanding and improving your Haskell
code.
Features
- Simple, declarative API that hides the busywork of configuring and running benchmarks.
- Sophisticated, high-resolution analysis capable of measuring operations that complete in a few hundred picoseconds.
- Multiple report formats: interactive HTML with charts, CSV, and JSON. You can supply your own templates to present results exactly the way you like.
- Linear regression helps isolate the impact of garbage collection and other environmental factors.
- Automatic cross-validation detects significant sources of noise (usually other activity on the system) so that you can trust the numbers you see.
Download
Grab the released package with cabal
:
cabal get criterion
cabal update
cabal install -j --disable-tests criterion
Or work from the latest development sources:
git clone https://github.com/haskell/criterion
cd criterion
cabal install
A complete example
Here is a full program that defines a group of three benchmarks. It demonstrates how little code you need to get started.
import Criterion.Main
fib m | m < 0 = error "negative!"
| otherwise = go m
where
go 0 = 0
go 1 = 1
go n = go (n - 1) + go (n - 2)
main =
defaultMain
[ bgroup
"fib"
[ bench "1" $ whnf fib 1
, bench "5" $ whnf fib 5
, bench "11" $ whnf fib 11
]
]
The full source for this example lives in
examples/Fibber.hs
.
Learn more
- Tutorial – a step-by-step guide maintained alongside the codebase.
- Active HTML report – explore an interactive
benchmark report generated by
criterion
. - Hackage package page – reference API docs, change logs, and release history.
- Issue tracker – file bugs or share improvements.