Skip to content

Instantly share code, notes, and snippets.

@hdevalence
Created December 20, 2013 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdevalence/8050365 to your computer and use it in GitHub Desktop.
Save hdevalence/8050365 to your computer and use it in GitHub Desktop.
cond vs elem test
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