$ ghc -O2 a.hs
$ time ./a
./a 1.39s user 1.70s system 69% cpu 4.479 total
$ ghc -O2 b.hs
$ time ./b
./b 1.52s user 1.73s system 73% cpu 4.448 total
Created
February 12, 2014 11:15
-
-
Save pasberth/8953682 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE NoImplicitPrelude #-} | |
| {-# LANGUAGE ExplicitForAll #-} | |
| import Prelude hiding (length) | |
| import Control.Monad | |
| incr :: Int -> Int | |
| {-# INLINE incr #-} | |
| incr = (+1) | |
| lengthCPS :: forall a. (Int -> Int) -> [a] -> Int | |
| lengthCPS cont [] = cont 0 | |
| lengthCPS cont (_:xs) = lengthCPS (cont . incr) xs | |
| length :: forall a. [a] -> Int | |
| length = lengthCPS id | |
| main :: IO () | |
| main = do | |
| forM_ [0..1000000] $ const $ do | |
| print $ length [0..10000] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE NoImplicitPrelude #-} | |
| {-# LANGUAGE ExplicitForAll #-} | |
| import Prelude hiding (length) | |
| import Control.Monad | |
| length :: forall a. [a] -> Int | |
| length [] = 0 | |
| length (_:xs) = 1 + length xs | |
| main :: IO () | |
| main = do | |
| forM_ [0..1000000] $ const $ do | |
| print $ length [0..10000] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment