<div dir="ltr">HI all,<div><br></div><div>I am messing around with bang patterns and noticed some huge differences between the total time as reported by the time tool and the .prof file. Below is the code used.</div><div>Without bang patterns:</div><div><div>module Main where</div><div><br></div><div>import Data.List</div><div><br></div><div>fastFibs = </div><div>  unfoldr nextFib (1, 1)</div><div>  where nextFib (x, y) = Just $ (x, (y, (x + y)))</div><div><br></div><div>main = <br></div><div>  putStrLn $ (show n) ++ "th fib is: " ++ (show $ fastFibs !! (n - 1))</div><div>  where n = 1000000</div></div><div><br></div><div>With bang patterns:</div><div><div>{-# LANGUAGE BangPatterns #-}</div><div><br></div><div>module Main where</div><div><br></div><div>import Data.List</div><div><br></div><div>fastFibs = </div><div>  unfoldr nextFib (1, 1)</div><div>  where nextFib (!x, !y) = Just $ (x, (y, (x + y)))</div><div><br></div><div>main = <br></div><div>  putStrLn $ (show n) ++ "th fib is: " ++ (show $ fastFibs !! (n - 1))</div><div>  where n = 1000000</div></div><div><br></div><div>when looking at the first through time and prof I get the following.</div><div>Without:</div><div><div>real    0m53.501s</div><div>user    0m0.015s</div><div>sys     0m0.328s</div><div>        Thu Oct 22 16:46 2015 Time and Allocation Profiling Report  (Final)</div><div><br></div><div>           fast-fib.exe +RTS -p -RTS</div><div><br></div><div>        total time  =        9.52 secs   (9520 ticks @ 1000 us, 1 processor)</div><div>        total alloc = 43,500,223,152 bytes  (excludes profiling overheads)</div></div><div><br></div><div>Please note the huge difference 53 vs 9 seconds.</div><div><br></div><div>With:</div><div><div>real    0m10.095s</div><div>user    0m0.031s</div><div>sys     0m0.344s</div><div>        Thu Oct 22 16:50 2015 Time and Allocation Profiling Report  (Final)</div><div><br></div><div>           fast-fib.exe +RTS -p -RTS</div><div><br></div><div>        total time  =        8.97 secs   (8971 ticks @ 1000 us, 1 processor)</div><div>        total alloc = 43,500,309,960 bytes  (excludes profiling overheads)</div></div><div><br></div><div>Here differences seem to be much smaller.</div><div><br></div><div>I am using Windows 8.1 64 bit, GHC 7.8.3 and measuring with the following line:</div><div>ghc Main.hs -o fast-fib.exe -O2 -prof && time ./fast-fib.exe +RTS -p && cat fast-fib.prof<br></div><div><br></div><div>Could someone please explain where the big difference is coming from and how to change the measuring approach to get more consistent results?</div><div><br></div><div>Best regards,</div><div>Javier de Vega Ruiz.</div></div>