-O causing a 7x slowdown (Map of IORef's)

Remi Turk rturk at science.uva.nl
Sat Apr 23 11:05:43 EDT 2005


Good afternoon,

the attached program is about 7 times slower when compiled
_with_ -O using ghc 6.4. Using ghc 6.2.1 with ddata's Map gives
the same behaviour.

Happy hacking,
Remi


% make

ghc --make -no-recomp    Main.hs -o nor
Chasing modules from: Main.hs
Compiling Main             ( Main.hs, Main.o )
Linking ...

ghc --make -no-recomp -O Main.hs -o opt
Chasing modules from: Main.hs
Compiling Main             ( Main.hs, Main.o )
Linking ...

time -p ./nor
real 1.77
user 1.75
sys 0.00

time -p ./opt
real 13.05
user 12.45
sys 0.06

-- 
Nobody can be exactly like me. Even I have trouble doing it.
-------------- next part --------------
module Main (main) where

import Data.Map         (Map, fromList, (!))
import Control.Monad    (replicateM_, liftM)
import Data.IORef       (IORef, newIORef, readIORef)

main = do
    mc <- fromList `liftM` mapM new [1..1000]
    replicateM_ 10000 $ mapM_ (get mc) [1..1000]
    where
        new     :: Integer -> IO (Integer, IORef Integer)
        new k   = do r <- newIORef 0; return (k, r)

        get     :: Map Integer (IORef Integer) -> Integer -> IO Integer
        get mc k= readIORef (mc ! k)
-------------- next part --------------
.PHONY: all

all:
	ghc --make -no-recomp    Main.hs -o nor
	ghc --make -no-recomp -O Main.hs -o opt
	time -p ./nor
	time -p ./opt


More information about the Glasgow-haskell-bugs mailing list