[Haskell-cafe] How to correctly benchmark code with Criterion?
claude at mathr.co.uk
Thu Oct 18 11:45:50 CEST 2012
On 18/10/12 10:23, Janek S. wrote:
> during past few days I spent a lot of time trying to figure out how to write Criterion benchmarks,
> so that results don't get skewed by lazy evaluation. I want to benchmark different versions of an
> algorithm doing numerical computations on a vector. For that I need to create an input vector
> containing a few thousand elements. I decided to create random data, but that really doesn't
> matter - I could have as well use infinite lists instead of random ones.
> The question is how to generate data so that its evaluation won't be included in the benchmark.
Something like this might work, not sure what the canonical way is.
main = do
let input = L.dataBuild gen
evaluate (rnf input)
bench "Lists" $ nf L.benchThisFunction input
I did use something like this in practice here:
More information about the Haskell-Cafe