-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.hs
35 lines (30 loc) · 928 Bytes
/
main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import Criterion.Main
import Control.DeepSeq
import qualified Data.Maybe as B
import qualified MapMaybe as F
main = do
rnf ints `seq` return ()
defaultMain
[ bgroup "simple"
[ bench "base" $ nf (B.mapMaybe half) ints
, bench "fold" $ nf (F.mapMaybe half) ints
]
, bgroup "after map"
[ bench "base" $ nf (B.mapMaybe half . map (+1)) ints
, bench "fold" $ nf (F.mapMaybe half . map (+1)) ints
]
, bgroup "after filter"
[ bench "base" $ nf (B.mapMaybe half . filter seven) ints
, bench "fold" $ nf (F.mapMaybe half . filter seven) ints
]
, bgroup "before map"
[ bench "base" $ nf (map (+1) . B.mapMaybe half) ints
, bench "fold" $ nf (map (+1) . F.mapMaybe half) ints
]
]
ints :: [Int]
ints = [-2 .. 8000]
half :: Int -> Maybe Int
half n = if even n then Just $! div n 2 else Nothing
seven :: Int -> Bool
seven x = quot x 10 == 7