[Haskell-cafe] How to write fast for loops
Niklas Hambüchen
mail at nh2.me
Sun Apr 27 20:10:00 UTC 2014
On 27/04/14 03:28, John Lato wrote:
> No, I mean this:
>
>> V.forM_ (V.enumFromN 1 n)
Hey John,
unfortunately that's not fast, and it eats all the RAMs.
Here comes the sad comparison of looping in Haskell:
- loop (maxBound :: Word32)
3 seconds, constant space
- forM_ [0..maxBound :: Word32]
36 seconds, constant space
- V.forM_ (V.enumFromTo 0 (maxBound :: Word32))
37 seconds, constant space
- V.forM_ (V.enumFromN 0 (fromIntegral (maxBound :: Word32)))
linear space -> crashes
All loops execute `return ()`.
:(
More information about the Haskell-Cafe
mailing list