[Haskell-cafe] How to write fast for loops
John Lato
jwlato at gmail.com
Sun Apr 27 22:18:13 UTC 2014
On Apr 27, 2014 1:10 PM, "Niklas Hambüchen" <mail at nh2.me> wrote:
>
> 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 ()`.
Hmm. Are you using regular vectors or unboxed? Also what sort of crash? Is
it a stack space overflow or are you on a 32-bit platform?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140427/b16381e8/attachment.html>
More information about the Haskell-Cafe
mailing list