criterion is a library that makes accurate microbenchmarking in Haskell easy.

Features

  • 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.

  • Output to active HTML (with Javascript charts), CSV, and JSON. Write your own report templates to customize exactly how your results are presented.

  • 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.

Download

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
               ]
  ]

(examples/Fibber.hs)

Ready to jump in?

I’ve worked hard to make criterion easy to learn, so that you can write dependable, accurate benchmarks without having to become a benchmarking expert.

Tutorial

I’m proud of the example-filled docs.

Documentation

If you run into problems, let me know.

Issues