Summing 1 billion consecutive integers
http://research.microsoft.com/en-us/um/people/simonpj/papers/ndp/haskell-beats-C.pdf
#include <stdio.h>
int main(int argc, char *argv[])
{
long a = 1000000000, b=0, i=0;
for (i; i <= a; ++i) b += i;
printf ("%lu\n",b);
return 0;
}
import qualified Data.Vector as V
main = print (V.foldl' (+) 0 (V.enumFromTo 1 1000000000) :: Int)
-- See stream fusion article above
gcc -O2 cbil.c -o cbil
ghc -O2 -fllvm hbil.hs
time ./cbil && time ./hbil
MacBook Pro Retina, 8 core, 2.3Ghz Intel i7
answer: 500000000500000000
real 0m0.003s
user 0m0.001s
sys 0m0.001s
answer: 500000000500000000
real 0m0.003s
user 0m0.001s
sys 0m0.001s