Created
May 3, 2012 19:27
-
-
Save kfl/2588483 to your computer and use it in GitHub Desktop.
Benchmark template for TiPL 2012, for testing map implementations
This file contains 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
-- Benchmark template for TiPL 2012, for testing map implementations | |
-- Compile with the command: ghc -O3 -W --make mapbench.hs -o mapbench | |
import qualified Criterion.Main as C | |
isPrime :: Integral a => a -> Bool | |
isPrime n = null [factor | factor <- [2..floor $ sqrt $ fromIntegral n] | |
, n `mod` factor == 0] | |
numbers = [2,3..] | |
kmap f = foldr (\x res -> f x : res) [] | |
main = do | |
let sizes = [ 10000, 100000, 1000000] | |
inputs = [(n, take n numbers) | n <- sizes] | |
benchmarks = [ C.bench (name ++ show n) $ C.nf mapprime ns | |
| (n, ns) <- inputs, | |
(name, mapprime) <- [("Data.List.map ", map$isPrime), | |
("kmap " , kmap$isPrime)]] | |
C.defaultMain benchmarks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment