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