Advertisement
Guest User

iteratebenchmark.hs

a guest
Jul 22nd, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Compiled with GHC 7.4.1 under Debian Wheezy amd64 using the "-O2"
  2. -- optimization, this takes 7.9 s on my Core2Duo@1.66GHz.
  3. -- If GHCs LLVM backend is used the time goes down to 6.1 s.
  4. -- It should be noted, that GHC automatically inlines 'logisticChaos' and
  5. -- 'iterateN', because there are used only once.
  6. --
  7. -- The manually inlined C++ version needs 7.9 s to do the same (g++ 4.7 "-O2").
  8. -- (see: http://kenta.blogspot.de/2013/07/abfsttwf-optimizing-iterate.html for the C++ code)
  9.  
  10. import Control.Exception (assert)
  11.  
  12. main = print $ iterateN (10^9) logisticChaos 0.5
  13.  
  14. logisticChaos :: Double -> Double
  15. logisticChaos x = 3.57 * x * (1-x)
  16.  
  17. iterateN :: Int -> (a -> a) -> a -> a
  18. iterateN n f = assert (n>=0) (go n) where
  19.     go 0 result = result
  20.     go n x = go (n-1) $! f x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement