4-- Copyright : (c) 2018 Harendra Kumar
7-- Maintainer : streamly@composewell.com
9import Control.DeepSeq (NFData)
10-- import Data.Functor.Identity (Identity, runIdentity)
11import System.Random (randomRIO)
12import qualified Streamly.Benchmark.Prelude as Ops
17-- We need a monadic bind here to make sure that the function f does not get
18-- completely optimized out by the compiler in some cases.
20-- | Takes a fold method, and uses it with a default source.
22benchIO :: (IsStream t, NFData b) => String -> (t IO Int -> IO b) -> Benchmark
23benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f . Ops.source
25-- | Takes a source, and uses it with a default drain/fold method.
26{-# INLINE benchSrcIO #-}
28 :: (t IO Int -> SerialT IO Int)
33 = bench name $ nfIO $ randomRIO (1,1) >>= Ops.toNull t . f
35{-# INLINE benchMonadicSrcIO #-}
36benchMonadicSrcIO :: String -> (Int -> IO ()) -> Benchmark
37benchMonadicSrcIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
40_benchId :: NFData b => String -> (Ops.Stream m Int -> Identity b) -> Benchmark
41_benchId name f = bench name $ nf (runIdentity . f) (Ops.source 10)
46 defaultMainWith (defaultConfig
50 , includeFirstIter = True
54 [ benchSrcIO asyncly "unfoldr" Ops.sourceUnfoldr
55 , benchSrcIO asyncly "unfoldrM" Ops.sourceUnfoldrM
56 , benchSrcIO asyncly "fromFoldable" Ops.sourceFromFoldable
57 , benchSrcIO asyncly "fromFoldableM" Ops.sourceFromFoldableM
58 , benchSrcIO asyncly "foldMapWith" Ops.sourceFoldMapWith
59 , benchSrcIO asyncly "foldMapWithM" Ops.sourceFoldMapWithM
60 , benchSrcIO asyncly "foldMapM" Ops.sourceFoldMapM
61 , benchIO "map" $ Ops.map' asyncly 1
62 , benchIO "fmap" $ Ops.fmap' asyncly 1
63 , benchIO "mapM" $ Ops.mapM asyncly 1
64 , benchSrcIO asyncly "unfoldrM maxThreads 1"
65 (maxThreads 1 . Ops.sourceUnfoldrM)
66 , benchSrcIO asyncly "unfoldrM maxBuffer 1 (x/10 ops)"
67 (maxBuffer 1 . Ops.sourceUnfoldrMN (Ops.value `div` 10))
68 , benchMonadicSrcIO "concatMapWith (2,x/2)"
69 (Ops.concatStreamsWith async 2 (Ops.value `div` 2))
70 , benchMonadicSrcIO "concatMapWith (x/2,2)"
71 (Ops.concatStreamsWith async (Ops.value `div` 2) 2)
74 [ benchSrcIO wAsyncly "unfoldr" Ops.sourceUnfoldr
75 , benchSrcIO wAsyncly "unfoldrM" Ops.sourceUnfoldrM
76 , benchSrcIO wAsyncly "fromFoldable" Ops.sourceFromFoldable
77 , benchSrcIO wAsyncly "fromFoldableM" Ops.sourceFromFoldableM
78 , benchSrcIO wAsyncly "foldMapWith" Ops.sourceFoldMapWith
79 , benchSrcIO wAsyncly "foldMapWithM" Ops.sourceFoldMapWithM
80 , benchSrcIO wAsyncly "foldMapM" Ops.sourceFoldMapM
81 , benchIO "map" $ Ops.map' wAsyncly 1
82 , benchIO "fmap" $ Ops.fmap' wAsyncly 1
83 , benchIO "mapM" $ Ops.mapM wAsyncly 1
84 , benchMonadicSrcIO "concatMapWith (2,x/2)"
85 (Ops.concatStreamsWith wAsync 2 (Ops.value `div` 2))
86 , benchMonadicSrcIO "concatMapWith (x/2,2)"
87 (Ops.concatStreamsWith wAsync (Ops.value `div` 2) 2)
89 -- unfoldr and fromFoldable are always serial and thereofore the same for
92 [ benchSrcIO aheadly "unfoldr" Ops.sourceUnfoldr
93 , benchSrcIO aheadly "unfoldrM" Ops.sourceUnfoldrM
94 , benchSrcIO aheadly "fromFoldableM" Ops.sourceFromFoldableM
95 -- , benchSrcIO aheadly "foldMapWith" Ops.sourceFoldMapWith
96 , benchSrcIO aheadly "foldMapWithM" Ops.sourceFoldMapWithM
97 , benchSrcIO aheadly "foldMapM" Ops.sourceFoldMapM
98 , benchIO "map" $ Ops.map' aheadly 1
99 , benchIO "fmap" $ Ops.fmap' aheadly 1
100 , benchIO "mapM" $ Ops.mapM aheadly 1
101 , benchSrcIO aheadly "unfoldrM maxThreads 1"
102 (maxThreads 1 . Ops.sourceUnfoldrM)
103 , benchSrcIO aheadly "unfoldrM maxBuffer 1 (x/10 ops)"
104 (maxBuffer 1 . Ops.sourceUnfoldrMN (Ops.value `div` 10))
105 -- , benchSrcIO aheadly "fromFoldable" Ops.sourceFromFoldable
106 , benchMonadicSrcIO "concatMapWith (2,x/2)"
107 (Ops.concatStreamsWith ahead 2 (Ops.value `div` 2))
108 , benchMonadicSrcIO "concatMapWith (x/2,2)"
109 (Ops.concatStreamsWith ahead (Ops.value `div` 2) 2)
111 -- XXX need to use smaller streams to finish in reasonable time
113 [ benchSrcIO parallely "unfoldr" Ops.sourceUnfoldr
114 , benchSrcIO parallely "unfoldrM" Ops.sourceUnfoldrM
115 --, benchSrcIO parallely "fromFoldable" Ops.sourceFromFoldable
116 , benchSrcIO parallely "fromFoldableM" Ops.sourceFromFoldableM
117 -- , benchSrcIO parallely "foldMapWith" Ops.sourceFoldMapWith
118 , benchSrcIO parallely "foldMapWithM" Ops.sourceFoldMapWithM
119 , benchSrcIO parallely "foldMapM" Ops.sourceFoldMapM
120 , benchIO "map" $ Ops.map' parallely 1
121 , benchIO "fmap" $ Ops.fmap' parallely 1
122 , benchIO "mapM" $ Ops.mapM parallely 1
123 -- Zip has only one parallel flavor
124 , benchIO "zip" Ops.zipAsync
125 , benchIO "zipM" Ops.zipAsyncM
126 , benchIO "zipAp" Ops.zipAsyncAp
127 -- Parallel stages in a pipeline
128 , benchIO "parAppMap" Ops.parAppMap
129 , benchIO "parAppSum" Ops.parAppSum
130 , benchMonadicSrcIO "concatMapWith (2,x/2)"
131 (Ops.concatStreamsWith parallel 2 (Ops.value `div` 2))
132 , benchMonadicSrcIO "concatMapWith (x/10,10)"
133 (Ops.concatStreamsWith parallel (Ops.value `div` 10) 10)
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