|
Re: loop performance bug: msg#00080lang.haskell.glasgow.bugs
duncan.coutts: > This sort of code runs very slowly when compared to the equivalent in C: This example uses unboxing and primops over Lemmih's and seems to run a bit faster: Lemmih's loops: ./a.out 1.35s user 0.00s system 99% cpu 1.359 total This code: ./a.out 0.99s user 0.00s system 98% cpu 1.008 total C: ./a.out 0.14s user 0.00s system 101% cpu 0.138 total > import GHC.Base > import GHC.IOBase > import GHC.Prim > import GHC.Pack > > data M = M (MutableByteArray# RealWorld) > > main = do > (M a) <- IO $ \s -> case newByteArray# (4#*#100#*#100#) s of (# s',ar #) > -> (# s',M ar #) > doFromTo 0 9999 $ \_ -> > doFromTo 0 99 $ \y -> > doFromTo 0 99 $ \x -> do > IO $ \s -> > case writeIntArray# (unsafeCoerce# a) (x *# (y +# 1#)) s of > s' -> (# s', () #) > > doFromTo (I# from) (I# to) action = do > let loop n | n ># to = return () > | otherwise = action n >> loop (n+#1#) > loop from Changing the index calculation (x *# (y +# 1#) to a constant halves the runtime, again, though that may not be very useful information ;) -- Don
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Broken Cabal, Iavor Diatchki |
|---|---|
| Next by Date: | Re: loop performance bug, Josef Svenningsson |
| Previous by Thread: | Re: loop performance bug, Sean Seefried |
| Next by Thread: | RE: loop performance bug, Simon Peyton-Jones |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |