3-- Copyright : (c) 2018 Harendra Kumar
6-- Maintainer : harendra.kumar@gmail.com
8import Control.DeepSeq (NFData)
9-- import Data.Functor.Identity (Identity, runIdentity)
10import System.Random (randomRIO)
11import qualified LinearOps as Ops
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.
19-- | Takes a fold method, and uses it with a default source.
21benchIO :: (IsStream t, NFData b) => String -> (t IO Int -> IO b) -> Benchmark
22benchIO name f = bench name $ nfIO $ randomRIO (1,1000) >>= f . Ops.source
24-- | Takes a source, and uses it with a default drain/fold method.
25{-# INLINE benchSrcIO #-}
27 :: (t IO Int -> SerialT IO Int)
32 = bench name $ nfIO $ randomRIO (1,1000) >>= Ops.toNull t . f
35_benchId :: NFData b => String -> (Ops.Stream m Int -> Identity b) -> Benchmark
36_benchId name f = bench name $ nf (runIdentity . f) (Ops.source 10)
44 [ -- Most basic, barely stream continuations running
45 benchSrcIO serially "unfoldr" $ Ops.sourceUnfoldr
46 , benchSrcIO serially "unfoldrM" Ops.sourceUnfoldrM
47 , benchSrcIO serially "fromList" Ops.sourceFromList
48 , benchSrcIO serially "fromListM" Ops.sourceFromListM
49 -- These are essentially cons and consM
50 , benchSrcIO serially "fromFoldable" Ops.sourceFromFoldable
51 , benchSrcIO serially "fromFoldableM" Ops.sourceFromFoldableM
52 -- These are essentially appends
53 , benchSrcIO serially "foldMapWith" Ops.sourceFoldMapWith
54 , benchSrcIO serially "foldMapWithM" Ops.sourceFoldMapWithM
56 , bgroup "elimination"
57 [ benchIO "toNull" $ Ops.toNull serially
58 , benchIO "uncons" Ops.uncons
59 , benchIO "nullHeadTail" Ops.nullHeadTail
60 , benchIO "mapM_" Ops.mapM_
61 , benchIO "toList" Ops.toList
62 , benchIO "foldr" Ops.foldr
63 , benchIO "foldrM" Ops.foldrM
64 , benchIO "foldl'" Ops.foldl
66 , benchIO "last" Ops.last
67 , benchIO "length" Ops.length
68 , benchIO "elem" Ops.elem
69 , benchIO "notElem" Ops.notElem
70 , benchIO "all" Ops.all
71 , benchIO "any" Ops.any
72 , benchIO "maximum" Ops.maximum
73 , benchIO "minimum" Ops.minimum
74 , benchIO "sum" Ops.sum
75 , benchIO "product" Ops.product
77 , bgroup "transformation"
78 [ benchIO "scan" Ops.scan
79 , benchIO "map" Ops.map
80 , benchIO "fmap" Ops.fmap
81 , benchIO "mapM" (Ops.mapM serially)
82 , benchIO "mapMaybe" Ops.mapMaybe
83 , benchIO "mapMaybeM" Ops.mapMaybeM
84 , bench "sequence" $ nfIO $ randomRIO (1,1000) >>= \n ->
85 (Ops.sequence serially) (Ops.sourceUnfoldrMAction n)
86 , benchIO "concat" Ops.concat
89 [ benchIO "filter-even" Ops.filterEven
90 , benchIO "filter-all-out" Ops.filterAllOut
91 , benchIO "filter-all-in" Ops.filterAllIn
92 , benchIO "take-all" Ops.takeAll
93 , benchIO "takeWhile-true" Ops.takeWhileTrue
94 , benchIO "takeWhileM-true" Ops.takeWhileMTrue
95 , benchIO "drop-all" Ops.dropAll
96 , benchIO "dropWhile-true" Ops.dropWhileTrue
97 , benchIO "dropWhileM-true" Ops.dropWhileMTrue
99 , benchIO "zip" $ Ops.zip
100 , benchIO "zipM" $ Ops.zipM
102 [ benchIO "mapM" Ops.composeMapM
103 , benchIO "map-with-all-in-filter" Ops.composeMapAllInFilter
104 , benchIO "all-in-filters" Ops.composeAllInFilters
105 , benchIO "all-out-filters" Ops.composeAllOutFilters
107 -- Scaling with same operation in sequence
108 , bgroup "compose-scaling"
109 [ benchIO "1" $ Ops.composeScaling 1
110 , benchIO "2" $ Ops.composeScaling 2
111 , benchIO "3" $ Ops.composeScaling 3
112 , benchIO "4" $ Ops.composeScaling 4
116 [ -- benchIO "unfoldr" $ Ops.toNull asyncly
117 benchSrcIO asyncly "unfoldrM" Ops.sourceUnfoldrM
118 -- , benchSrcIO asyncly "fromFoldable" Ops.sourceFromFoldable
119 , benchSrcIO asyncly "fromFoldableM" Ops.sourceFromFoldableM
120 -- , benchSrcIO asyncly "foldMapWith" Ops.sourceFoldMapWith
121 , benchSrcIO asyncly "foldMapWithM" Ops.sourceFoldMapWithM
122 , benchIO "mapM" $ Ops.mapM asyncly
125 [ -- benchIO "unfoldr" $ Ops.toNull wAsyncly
126 benchSrcIO wAsyncly "unfoldrM" Ops.sourceUnfoldrM
127 -- , benchSrcIO wAsyncly "fromFoldable" Ops.sourceFromFoldable
128 , benchSrcIO wAsyncly "fromFoldableM" Ops.sourceFromFoldableM
129 -- , benchSrcIO wAsyncly "foldMapWith" Ops.sourceFoldMapWith
130 , benchSrcIO wAsyncly "foldMapWithM" Ops.sourceFoldMapWithM
131 , benchIO "mapM" $ Ops.mapM wAsyncly
133 -- unfoldr and fromFoldable are always serial and thereofore the same for
136 [ -- benchIO "unfoldr" $ Ops.toNull aheadly
137 benchSrcIO aheadly "unfoldrM" Ops.sourceUnfoldrM
138 -- , benchSrcIO aheadly "fromFoldable" Ops.sourceFromFoldable
139 , benchSrcIO aheadly "fromFoldableM" Ops.sourceFromFoldableM
140 -- , benchSrcIO aheadly "foldMapWith" Ops.sourceFoldMapWith
141 , benchSrcIO aheadly "foldMapWithM" Ops.sourceFoldMapWithM
142 , benchIO "mapM" $ Ops.mapM aheadly
144 -- XXX need to use smaller streams to finish in reasonable time
146 [ --benchIO "unfoldr" $ Ops.toNull parallely
147 benchSrcIO parallely "unfoldrM" Ops.sourceUnfoldrM
148 --, benchSrcIO parallely "fromFoldable" Ops.sourceFromFoldable
149 , benchSrcIO parallely "fromFoldableM" Ops.sourceFromFoldableM
150 -- , benchSrcIO parallely "foldMapWith" Ops.sourceFoldMapWith
151 , benchSrcIO parallely "foldMapWithM" Ops.sourceFoldMapWithM
152 , benchIO "mapM" $ Ops.mapM parallely
153 -- Zip has only one parallel flavor
154 , benchIO "zip" $ Ops.zipAsync
155 , benchIO "zipM" $ Ops.zipAsyncM
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list