[Haskell-cafe] Fusion for fun and profi (Was: newbie
stefanor at cox.net
Sun Oct 28 16:30:38 EDT 2007
On Sun, Oct 28, 2007 at 01:25:19PM -0700, Don Stewart wrote:
> Finally, we can manually translate the C code into a confusing set of nested
> loops with interleaved IO,
> main = loop 1
> loop !i | i > 10000 = return ()
> | otherwise = if i == go i 0 1 then print i >> loop (i+1)
> else loop (i+1)
> go !i !s !j | j <= i-1 = if i `rem` j == 0 then go i (s+j) (j+1)
> else go i s (j+1)
> | otherwise = s
> And we get *no speed benefit* at all!
> time ./A-loop 1.24s user 0.00s system 98% cpu 1.256 total
> So the lesson is: write in a high level style, and the compiler can do the work
> for you. Or, GHC is pretty smart on high level code.
IO blocks unboxing in GHC. How fast is your mock-C code refactored to
do IO outside of the loops only?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20071028/4561c2a2/attachment.bin
More information about the Haskell-Cafe