[Haskell-cafe] How to benckmark a Word64 -> Bool?

Charles-Pierre Astolfi cpa at crans.org
Wed Feb 19 17:36:07 UTC 2014


Hi,

I have a Word64 -> Bool function called only012 that returns True iff the
digits in base 10 are 0, 1 or 2.
I wand to make sure that I'm competitive with C, so I wrote the following
code:

Haskell version:
http://lpaste.net/100129

C version:
http://lpaste.net/100128

$ ghc --make -O3 303only012.hs && time ./303only012 50000000 > /dev/null
./303only012 50000000 > /dev/null  21.44s user 0.41s system 91% cpu 23.754
total

$ g++ -O3 303only012.cpp -o 303cpponly012 && time ./303cpponly012 50000000
> /dev/null
./303cpponly012 50000000 > /dev/null  13.87s user 0.03s system 95% cpu
14.577 total

So there's a difference, but I'm not sure if it's related to my algorithm
or related to IO/RTS.

The core output of only012 looks quite tight: http://lpaste.net/100130

Am I doing the IO part right, that is fast IO that is not screwing my
benckmark? I'm not so sure about that since I use a convoluted way to print
the boolean result in Haskell.

Cheers,
--
Cp
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140219/b38c685d/attachment.html>


More information about the Haskell-Cafe mailing list