I know that ghc performs hardly any optimisation if called without -O or -O2.
However, is it necessary that just adding a single function definition to a
program *without* calling this function increases execution time by 50%?
(ghc-2.08)

Example:

{-
fromStepTo :: Int -> Int -> Int -> [Int]
fromStepTo start step end
  | start > end = []
  | otherwise   = start : fromStepTo (start+step) step end
-}

all2 :: (a -> Bool) -> [a] -> Bool
all2 p []     = True
all2 p (x:xs) = p x && all2 p xs


main = putStr (show (all2 even [2,4..2000000]))



If `fromStepTo' is commented out as above I measure:

64,001,320 bytes allocated in the heap
        300 bytes maximum residency (0.0%, 6 sample(s))
         52 garbage collections performed (6 major, 46 minor)

  INIT  time    0.01s  (  0.11s elapsed)
  MUT   time    8.04s  (  8.51s elapsed)
  GC    time    2.51s  (  2.70s elapsed)
  Total time   10.56s  ( 11.32s elapsed)


However, deleting `{-' and `-}' results in

 64,001,320 bytes allocated in the heap
        300 bytes maximum residency (0.0%, 6 sample(s))
         52 garbage collections performed (6 major, 46 minor)

  INIT  time    0.01s  (  0.14s elapsed)
  MUT   time   12.17s  ( 12.49s elapsed)
  GC    time    2.44s  (  2.68s elapsed)
  Total time   14.62s  ( 15.31s elapsed)



With -O both versions give the same result:

 24,000,852 bytes allocated in the heap
        232 bytes maximum residency (0.0%, 5 sample(s))
         21 garbage collections performed (5 major, 16 minor)

  INIT  time    0.02s  (  0.07s elapsed)
  MUT   time    2.79s  (  2.99s elapsed)
  GC    time    2.13s  (  2.31s elapsed)
  Total time    4.94s  (  5.37s elapsed)


Olaf
-- 
OLAF CHITIL, Lehrstuhl fuer Informatik II, RWTH Aachen, 52056 Aachen, Germany
             Tel: (+49/0)241/80-21212; Fax: (+49/0)241/8888-217
             URL: http://www-i2.informatik.rwth-aachen.de/~chitil/

Reply via email to