Created
December 20, 2013 04:16
-
-
Save hdevalence/8050365 to your computer and use it in GitHub Desktop.
cond vs elem test
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
import System.Environment (getArgs) | |
import Control.Monad (liftM) | |
import Criterion.Main | |
testElemS :: String -> Bool | |
testElemS = flip elem ["a", "b", "c", "d", "e"] | |
testCondS :: String -> Bool | |
testCondS x = (x == "a" || x == "b" || x == "c" || x == "d" || x == "e") | |
testElem :: Char -> Bool | |
testElem = flip elem ['a', 'b', 'c', 'd', 'e'] | |
testCond :: Char -> Bool | |
testCond x = (x == 'a' || x == 'b' || x == 'c' || x == 'd' || x == 'e') | |
main = defaultMain [ | |
bgroup "cond String" [ bench "a" $ nf testCondS "a" | |
, bench "e" $ nf testCondS "e" | |
, bench "z" $ nf testCondS "z" | |
] | |
, bgroup "elem String" [ bench "a" $ nf testElemS "a" | |
, bench "e" $ nf testElemS "e" | |
, bench "z" $ nf testElemS "z" | |
] | |
, bgroup "cond Char" [ bench "a" $ nf testCond 'a' | |
, bench "e" $ nf testCond 'e' | |
, bench "z" $ nf testCond 'z' | |
] | |
, bgroup "elem Char" [ bench "a" $ nf testElem 'a' | |
, bench "e" $ nf testElem 'e' | |
, bench "z" $ nf testElem 'z' | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment