logo       

Re: loop performance bug: msg#00075

lang.haskell.glasgow.bugs

Subject: Re: loop performance bug

On Tue, 15 Mar 2005 02:06:06 +0100, Lemmih <lemmih@xxxxxxxxx> wrote:
> We can make it a little faster by not doing bound checks:
>
> > test4 :: IO ()
> > test4 = do
> > (arr :: IOUArray Int Bool) <- newArray_ (0,100*100-1)
> > doFromTo 0 9999 $ \_ ->
> > doFromTo 0 99 $ \y ->
> > doFromTo 0 99 $ \x ->
> > unsafeWrite arr (x*(y+1)) False
>
> Timings (compiled with -O2):
> test1: 12.6s
> test2: 8.5s
> test3: 1.9s
> test4: 1.3s

A small update making the test more fair:

> test5 :: IO ()
> test5 = do
> (arr :: IOUArray Int Int) <- newArray_ (0,100*100-1)
> doFromTo 0 9999 $ \_ ->
> doFromTo 0 99 $ \y ->
> doFromTo 0 99 $ \x ->
> unsafeWrite arr (x*(y+1)) 0

I previously though that Bools were optimized away, guess I was wrong.
test5: 0.8s

--
Friendly,
Lemmih


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise