loop performance bug

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Mon Mar 14 20:48:28 EST 2005


On Tue, 2005-03-15 at 02:06 +0100, Lemmih 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

that was test3 that Josef gave? He only got double performance. You get
quad performance improvement.

> test4: 1.3s

Nice, my GUI visualiser now runs almost 25% faster (using test4 style vs
previous test2 style loops). It can now generate enough X traffic to
make the X server take 25% cpu time whereas previously it only got X
doing 15-20%.

I realised there was a performance bug when I commented out the Sim.step
from the inner loop and found that the visuliser speed only doubled, but
sommenting out the loops entirely gave the expected order or magnitude
speed increase. It seemed the majority of the time was being spent in
loop overhead! :-(

Duncan




More information about the Glasgow-haskell-bugs mailing list