Benchmarking using the criterion library
Profiling aside, benchmarking the time a calculation takes to perform is a direct indicator of real-world performance. Benchmarking Haskell applications is pretty much dominated by the criterion library. There is a system called nofib
, which is used to benchmark GHC itself, but for applications criterion is superior. Criterion even produces interactive web pages describing the results of benchmarks, which is a nice feature.
This text is written for criterion-1.1.1.0. Obviously, the criterion
package needs to be installed:
cabal install criterion # or: stack install criterion
A criterion benchmark suite is created as a normal Haskell program. An example is this:
–– file: benchmark.hs import Criterion.Main import Data.List (foldl') main = defaultMain [ bgroup "sum" [ bench "sum" $ whnf sum [1..1000000] , bench "foldr" $ whnf (foldr (+) 0) [1..1000000] , bench "foldl...