The Computer Language Benchmarks Game: pidigits

Hi all, I recently decided to rewrite the pidigits benchmark of the debian shootout (shootout.alioth.debian.org) as toy project. However, it seems that on my machine, the code seems to be more performant than both the current entry and the proposed replacement (see http://www.haskell.org/haskellwiki/Shootout/Pidigits) for the same number of lines. Do you think it might be worth submitting my entry? Here is my code,: {-# OPTIONS -O2 -optc-O3 #-} -- -- The Great Computer Language Shootout -- http://shootout.alioth.debian.org/ -- by Arnaud Payement -- import System data F = F Integer Integer Integer Integer extract s@(F k n a d) = ((n*3+a) `div` d, (n*4+a) `div` d, s) update (F k n a d) = F (k+1) (n*k) ((a+n*2)*y) (d*y) where y = 2*k+1 next state = let (u, v, s'@(F k n a d)) = extract (update state) in if (n > a || (u /= v)) then next s' else (show u, F k (n*10) ((a-d*u)*10) d) digits = ("", (F 1 1 0 1)):[next state | state <- map snd digits] pr (d:t) k n | k > n = putStr "" | k `mod` 10 /= 0 = putStr d >> pr t (k+1) n | otherwise = putStrLn (d ++ "\t:" ++ show k) >> pr t (k+1) n main = pr (map fst (tail digits)) 1 . read . head =<< getArgs Best, Arnaud

arnaud.payement:
Hi all,
I recently decided to rewrite the pidigits benchmark of the debian shootout (shootout.alioth.debian.org) as toy project. However, it seems that on my machine, the code seems to be more performant than both the current entry and the proposed replacement (see http://www.haskell.org /haskellwiki/Shootout/Pidigits) for the same number of lines. Do you think it might be worth submitting my entry? Here is my code,:
If it is faster, and correct, please submit it

Hi, By the way: Would it be considered good style to include QuickTest properties into the pidigit submission? Matthias.

By the way, I did submit my solution. It improved the score a bit but it is
still very memory hungry.
----- Original Message -----
From: "Don Stewart"
matthias.goergens:
Hi,
By the way: Would it be considered good style to include QuickTest properties into the pidigit submission?
Not in the submission, no.

That's fixed in GHC 6.10.2 + though, IIRC. arnaud.payement:
By the way, I did submit my solution. It improved the score a bit but it is still very memory hungry.
----- Original Message ----- From: "Don Stewart"
To: "Matthias Görgens" Cc: "Arnaud Payement" ; Sent: Saturday, May 23, 2009 10:16 PM Subject: Re: [Haskell-cafe] The Computer Language Benchmarks Game: pidigits matthias.goergens:
Hi,
By the way: Would it be considered good style to include QuickTest properties into the pidigit submission?
Not in the submission, no.

:
By the way, I did submit my solution. It improved the score a bit but it is still very memory hungry.
a bit? Currentlly it is the fastest in 32 bit . the memory/speed problems happens in 64 bit benchmarks. I suppose that the speed is related with the memory leak that will be fixed, Dons said. Event there doubled the performance of the previous entry. Just to learn; how this last version is faster than the previous entry? This new version does not use strictness annotations. Is this an example where laziness pays (and indeed causes the memory leak in the 64 bit architectures?

It is quite hard for me to tell why this entry is faster than the one one as I used the C entry as a starting point which I then refactored multiple times to ensure that the solution is closer to what one who right in Haskell. The only big difference I can see between the two is the different usage of list comprehension. The preceding entry was building a list which is then refined using the str method to end up being the list of digits. On the other hand my version use list continuation to recursively build a list of (digit, state) and then you simply have to print (map fst (tail digits)). I did not use the strictness annotations because they did not improve the performance when I tried to add them and I thought it is better to show Haskell as one would naturally write it. ----- Original Message ----- From: Alberto G. Corona To: Arnaud Payement ; haskell-cafe@haskell.org Sent: Monday, May 25, 2009 10:54 AM Subject: Re: [Haskell-cafe] The Computer Language Benchmarks Game: pidigits
:
By the way, I did submit my solution. It improved the score a bit but it is still very memory hungry.
a bit? Currentlly it is the fastest in 32 bit . the memory/speed problems happens in 64 bit benchmarks. I suppose that the speed is related with the memory leak that will be fixed, Dons said. Event there doubled the performance of the previous entry. Just to learn; how this last version is faster than the previous entry? This new version does not use strictness annotations. Is this an example where laziness pays (and indeed causes the memory leak in the 64 bit architectures?

That is amazing! It's the fastest 32-bit entry, good job.
On Sat, May 23, 2009 at 5:33 PM, Arnaud Payement
By the way, I did submit my solution. It improved the score a bit but it is still very memory hungry.
----- Original Message ----- From: "Don Stewart"
To: "Matthias Görgens" Cc: "Arnaud Payement" ; Sent: Saturday, May 23, 2009 10:16 PM Subject: Re: [Haskell-cafe] The Computer Language Benchmarks Game: pidigits matthias.goergens:
Hi,
By the way: Would it be considered good style to include QuickTest properties into the pidigit submission?
Not in the submission, no.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (5)
-
Alberto G. Corona
-
Arnaud Payement
-
Daniel Peebles
-
Don Stewart
-
Matthias Görgens