3-- Copyright : (c) 2018 Harendra Kumar
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
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 :: (IsStream t, NFData b) => String -> (t IO Int -> IO b) -> Benchmark
19benchIO name f = bench name $ nfIO $ randomRIO (1,1000) >>= f . Ops.source
22 :: (t IO Int -> SerialT IO Int)
27 = bench name $ nfIO $ randomRIO (1,1000) >>= Ops.toNull t . f
29benchIOAppend :: (NFData b) => String -> (Int -> IO b) -> Benchmark
30benchIOAppend name f = bench name $ nfIO $ randomRIO (1,1000) >>= f
32_benchId :: NFData b => String -> (Ops.Stream m Int -> Identity b) -> Benchmark
33_benchId name f = bench name $ nf (runIdentity . f) (Ops.source 10)
40 [ benchIO "unfoldr" $ Ops.toNull serially
41 , benchSrcIO serially "fromFoldable" Ops.sourceFromFoldable
42 , benchSrcIO serially "foldMapWith" Ops.sourceFoldMapWith
43 , benchSrcIO serially "unfoldrM" Ops.sourceUnfoldrM
44 , benchSrcIO serially "fromFoldableM" Ops.sourceFromFoldableM
45 , benchSrcIO serially "foldMapWithM" Ops.sourceFoldMapWithM
47 -- unfoldr and fromFoldable are always serial and thereofore the same for
50 [ -- benchIO "unfoldr" $ Ops.toNull aheadly
51 -- , benchSrcIO aheadly "fromFoldable" Ops.sourceFromFoldable
52 benchSrcIO aheadly "foldMapWith" Ops.sourceFoldMapWith
53 , benchSrcIO aheadly "unfoldrM" Ops.sourceUnfoldrM
54 , benchSrcIO aheadly "fromFoldableM" Ops.sourceFromFoldableM
55 , benchSrcIO aheadly "foldMapWithM" Ops.sourceFoldMapWithM
58 [ -- benchIO "unfoldr" $ Ops.toNull asyncly
59 -- , benchSrcIO asyncly "fromFoldable" Ops.sourceFromFoldable
60 benchSrcIO asyncly "foldMapWith" Ops.sourceFoldMapWith
61 , benchSrcIO asyncly "unfoldrM" Ops.sourceUnfoldrM
62 , benchSrcIO asyncly "fromFoldableM" Ops.sourceFromFoldableM
63 , benchSrcIO asyncly "foldMapWithM" Ops.sourceFoldMapWithM
65 -- XXX need to use smaller streams to finish in reasonable time
67 [ --benchIO "unfoldr" $ Ops.toNull parallely
68 --, benchSrcIO parallely "fromFoldable" Ops.sourceFromFoldable
69 --, benchSrcIO parallely "foldMapWith" Ops.sourceFoldMapWith
70 -- , benchSrcIO parallely "unfoldrM" Ops.sourceUnfoldrM
71 -- , benchSrcIO parallely "fromFoldableM" Ops.sourceFromFoldableM
72 -- , benchSrcIO parallely "foldMapWithM" Ops.sourceFoldMapWithM
75 -- XXX this is the same foldMapWith in the above benchmarks, need to dedup
76 -- this one provides a single place comparsion of all types and uses
77 -- smaller stream size for faster benchmarking. We can use the same for
78 -- above benchmarks and remove this.
80 [ benchIOAppend "serially" $ Ops.append serially
81 , benchIOAppend "wSerially" $ Ops.append wSerially
82 , benchIOAppend "aheadly" $ Ops.append aheadly
83 , benchIOAppend "asyncly" $ Ops.append asyncly
84 , benchIOAppend "wAsyncly" $ Ops.append wAsyncly
85 , benchIOAppend "parallely" $ Ops.append parallely
87 , bgroup "elimination"
88 [ benchIO "toNull" $ Ops.toNull serially
89 , benchIO "toList" Ops.toList
90 , benchIO "fold" Ops.foldl
91 , benchIO "last" Ops.last
93 , bgroup "transformation"
94 [ benchIO "scan" Ops.scan
95 , benchIO "map" Ops.map
96 , benchIO "mapM" Ops.mapM
97 , benchIO "concat" Ops.concat
100 [ benchIO "filter-even" Ops.filterEven
101 , benchIO "filter-all-out" Ops.filterAllOut
102 , benchIO "filter-all-in" Ops.filterAllIn
103 , benchIO "take-all" Ops.takeAll
104 , benchIO "takeWhile-true" Ops.takeWhileTrue
105 , benchIO "drop-all" Ops.dropAll
106 , benchIO "dropWhile-true" Ops.dropWhileTrue
108 , benchIO "zip" Ops.zip
110 [ benchIO "mapM" Ops.composeMapM
111 , benchIO "map-with-all-in-filter" Ops.composeMapAllInFilter
112 , benchIO "all-in-filters" Ops.composeAllInFilters
113 , benchIO "all-out-filters" Ops.composeAllOutFilters
115 , bgroup "compose-scaling"
116 -- Scaling with same operation in sequence
117 [ benchIO "1" $ Ops.composeScaling 1
118 , benchIO "2" $ Ops.composeScaling 2
119 , benchIO "3" $ Ops.composeScaling 3
120 , benchIO "4" $ Ops.composeScaling 4
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