on c8b32f2 help sign in
streamly/benchmark/Linear.hs
72 lines 2.5 kB history raw
1-- |
2-- Module : Main
3-- Copyright : (c) 2018 Harendra Kumar
4--
5-- License : BSD3
6-- Maintainer : harendra.kumar@gmail.com
8import Control.DeepSeq (NFData)
9import Data.Functor.Identity (Identity, runIdentity)
10import System.Random (randomRIO)
11import qualified LinearOps as Ops
13import Streamly
14import Gauge
16-- We need a monadic bind here to make sure that the function f does not get
17-- completely optimized out by the compiler in some cases.
18benchIO :: (NFData b) => String -> (Ops.Stream m Int -> IO b) -> Benchmark
19benchIO name f = bench name $ nfIO $ randomRIO (1,1000) >>= f . Ops.source
21benchIOAppend :: (NFData b) => String -> (Int -> IO b) -> Benchmark
22benchIOAppend name f = bench name $ nfIO $ randomRIO (1,1000) >>= f
24_benchId :: (NFData b) => String -> (Ops.Stream m Int -> Identity b) -> Benchmark
25_benchId name f = bench name $ nf (runIdentity . f) (Ops.source 10)
27main :: IO ()
28main = do
29 defaultMain
30 [ bgroup "elimination"
31 [ benchIO "toNull" Ops.toNull
32 , benchIO "toList" Ops.toList
33 , benchIO "fold" Ops.foldl
34 , benchIO "last" Ops.last
35 ]
36 , bgroup "transformation"
37 [ benchIO "scan" Ops.scan
38 , benchIO "map" Ops.map
39 , benchIO "mapM" Ops.mapM
40 , benchIO "concat" Ops.concat
41 ]
42 , bgroup "filtering"
43 [ benchIO "filter-even" Ops.filterEven
44 , benchIO "filter-all-out" Ops.filterAllOut
45 , benchIO "filter-all-in" Ops.filterAllIn
46 , benchIO "take-all" Ops.takeAll
47 , benchIO "takeWhile-true" Ops.takeWhileTrue
48 , benchIO "drop-all" Ops.dropAll
49 , benchIO "dropWhile-true" Ops.dropWhileTrue
50 ]
51 , benchIO "zip" Ops.zip
52 , bgroup "append"
53 [ benchIOAppend "serially" $ Ops.append serially
54 , benchIOAppend "wSerially" $ Ops.append wSerially
55 , benchIOAppend "asyncly" $ Ops.append asyncly
56 , benchIOAppend "wAsyncly" $ Ops.append wAsyncly
57 , benchIOAppend "parallely" $ Ops.append parallely
58 ]
59 , bgroup "compose"
60 [ benchIO "mapM" Ops.composeMapM
61 , benchIO "map-with-all-in-filter" Ops.composeMapAllInFilter
62 , benchIO "all-in-filters" Ops.composeAllInFilters
63 , benchIO "all-out-filters" Ops.composeAllOutFilters
64 ]
65 , bgroup "compose-scaling"
66 -- Scaling with same operation in sequence
67 [ benchIO "1" $ Ops.composeScaling 1
68 , benchIO "2" $ Ops.composeScaling 2
69 , benchIO "3" $ Ops.composeScaling 3
70 , benchIO "4" $ Ops.composeScaling 4
71 ]
72 ]