[Haskell-cafe] Haskell performance question

Dan Piponi dpiponi at gmail.com
Thu Nov 8 14:12:04 EST 2007


Bulat,

The strictness gave me something like a 10% performance increase
making the Haskell code more than 10 times slower than the C. Is this
the right type of array to use for performance?
--
Dan

On Nov 8, 2007 10:36 AM, Bulat Ziganshin <bulat.ziganshin at gmail.com> wrote:
> Hello Dan,
>
> Thursday, November 8, 2007, 9:33:12 PM, you wrote:
>
> > main = do
> >    a <- newArray (0,n-1) 1.0 :: IO (IOUArray Int Double)
> >    forM_ [0..n-2] $ \i -> do { x <- readArray a i; y <- readArray a
> > (i+1); writeArray a (i+1) (x+y) }
> >    x <- readArray a (n-1)
> >    print x
>
> 1. ghc doesn't implement loop unrolling, even in -O2 mode
> 2. forM_ may have its own overheads, i'm not sure
> 3. add strictness annotations:
>
> forM_ [0..n-2] $ \i -> do { return $! i;
>                             x <- readArray a i; return $! x;
>                             y <- readArray a (i+1); return $! y;
>                             writeArray a (i+1) (x+y) }
>
> such cycle should be approx. 3-10 times slower than C one
>
> --
> Best regards,
>  Bulat                            mailto:Bulat.Ziganshin at gmail.com
>
>


More information about the Haskell-Cafe mailing list