[Haskell-cafe] How to correctly benchmark code with Criterion?

Alfredo Di Napoli alfredo.dinapoli at gmail.com
Thu Oct 18 11:49:03 CEST 2012


I don't know if you have already read them,
but Tibell's slides on High Performance Haskell are pretty good:

http://www.slideshare.net/tibbe/highperformance-haskell

There is a section at the end where he runs several tests using Criterion.

HTH,
A.

On 18 October 2012 11:45, Claude Heiland-Allen <claude at mathr.co.uk> wrote:

> Hi Janek,
>
>
> 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.
>>
>
> [snip]
>
>
>  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.
>
> ---8<---
> main = do
>   ...
>   let input = L.dataBuild gen
>   evaluate (rnf input)
>   defaultMain
>      ...
>      bench "Lists" $ nf L.benchThisFunction input
>      ...
> ---8<---
>
> I did use something like this in practice here:
>
> https://gitorious.org/bitwise/**bitwise/blobs/master/extra/**
> benchmark.hs#line155<https://gitorious.org/bitwise/bitwise/blobs/master/extra/benchmark.hs#line155>
>
> Thanks,
>
>
> Claude
> --
> http://mathr.co.uk
>
>
> ______________________________**_________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/**mailman/listinfo/haskell-cafe<http://www.haskell.org/mailman/listinfo/haskell-cafe>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121018/7a36fc49/attachment.htm>


More information about the Haskell-Cafe mailing list