criterion is a library that makes accurate microbenchmarking in Haskell easy.
The simple API hides a lot of automation and details that you shouldn’t need to worry about.
Sophisticated, high-resolution analysis can accurately measure operations that run in as little as a few hundred picoseconds.
Linear regression model allows measurement of the effects of garbage collection and other factors.
Measurements are cross-validated to ensure that sources of significant noise (usually other activity on the system) can be identified.
Get the source code:
cabal get criterion
Or install from source:
cabal update cabal install -j --disable-tests criterion
Or use the bleeding edge:
git clone https://github.com/bos/criterion cd criterion cabal install
A complete example
This is a complete program that defines a group of three benchmarks.
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 ] ]