[Haskell-cafe] Reasoning about performance

Scott Pakin pakin at lanl.gov
Wed Sep 4 17:33:14 CEST 2013


On 09/03/2013 06:02 PM, Carter Schonwald wrote:
> It's also worth adding that ghci does a lot less optimization than ghc.

Yes, I discovered that before I posted.  Note from my initial message
that I used ghc to compile, then loaded the compiled module into ghci:

      Prelude> :!ghc -c -O2 allpairs.hs
      Prelude> :load allpairs
      Ok, modules loaded: AllPairs.
      Prelude AllPairs> :m +Control.DeepSeq
      Prelude Control.DeepSeq AllPairs> :show modules
      AllPairs         ( allpairs.hs, allpairs.o )

> Likewise, the best tool for doing performance benchmarking is the excellent Criterion library.

Ah, I didn't know about Criterion; that does look useful.  For the
record, here's what Criterion reports for my three all-pairs
implementations:

     Prelude Criterion.Main AllPairs> defaultMain [bench "allPairs1" $ nf allPairs1 [1..10000]]
                                  ...
     mean: 5.184160 s, lb 5.156169 s, ub 5.212516 s, ci 0.950
     std dev: 144.4938 ms, lb 127.3414 ms, ub 164.8774 ms, ci 0.950

     Prelude Criterion.Main AllPairs> defaultMain [bench "allPairs2" $ nf allPairs2 [1..10000]]
                                  ...
     mean: 2.310527 s, lb 2.290451 s, ub 2.329349 s, ci 0.950

     Prelude Criterion.Main AllPairs> defaultMain [bench "allPairs3" $ nf allPairs3 [1..10000]]
                                  ...
     mean: 10.05609 s, lb 10.02453 s, ub 10.08866 s, ci 0.950

As before, allPairs2 is the fastest, followed by allPairs1, with
allPairs3 in last place.

-- Scott




More information about the Haskell-Cafe mailing list