on master help sign in
Add micro benchmarks for convering exposed APIs in Fold
fc25c42adithyaov
benchmark/Streamly/Benchmark/Data/Fold.hs+33−1
@@ -15,7 +15,7 @@ import Data.Monoid (Last(..), Sum(..))
15import System.Random (randomRIO)
15import System.Random (randomRIO)
16import Prelude (IO, Int, Double, String, (>), (<*>), (<$>), (+), ($),
16import Prelude (IO, Int, Double, String, (>), (<*>), (<$>), (+), ($),
17 (<=), Monad(..), (==), Maybe(..), (.), fromIntegral,
17 (<=), Monad(..), (==), Maybe(..), (.), fromIntegral,
18− compare, (>=), concat, seq)
18+ compare, (>=), concat, seq, Either(..), odd)
19
19
20import qualified Streamly.Prelude as S
20import qualified Streamly.Prelude as S
21import qualified Streamly.Internal.Data.Fold as FL
21import qualified Streamly.Internal.Data.Fold as FL
@@ -66,6 +66,7 @@ o_1_space_serial_elimination value =
66 [ bgroup "serially"
66 [ bgroup "serially"
67 [ bgroup "elimination"
67 [ bgroup "elimination"
68 [ benchIOSink value "drain" (S.fold FL.drain)
68 [ benchIOSink value "drain" (S.fold FL.drain)
69+ , benchIOSink value "drainBy" (S.fold (FL.drainBy return))
69 , benchIOSink value "drainN" (S.fold (IFL.drainN value))
70 , benchIOSink value "drainN" (S.fold (IFL.drainN value))
70 , benchIOSink
71 , benchIOSink
71 value
72 value
@@ -116,9 +117,17 @@ o_1_space_serial_elimination value =
116 value
117 value
117 "foldMap"
118 "foldMap"
118 (S.fold (FL.foldMap (Last . Just)))
119 (S.fold (FL.foldMap (Last . Just)))
120+ , benchIOSink
121+ value
122+ "foldMapM"
123+ (S.fold (FL.foldMapM (return . Last . Just)))
119 , benchIOSink value "index" (S.fold (FL.index (value + 1)))
124 , benchIOSink value "index" (S.fold (FL.index (value + 1)))
120 , benchIOSink value "head" (S.fold FL.head)
125 , benchIOSink value "head" (S.fold FL.head)
121 , benchIOSink value "find" (S.fold (FL.find (== (value + 1))))
126 , benchIOSink value "find" (S.fold (FL.find (== (value + 1))))
127+ , benchIOSink
128+ value
129+ "lookup"
130+ (S.fold (IFL.lmap (\a -> (a, a)) (FL.lookup (value + 1))))
122 , benchIOSink
131 , benchIOSink
123 value
132 value
124 "findIndex"
133 "findIndex"
@@ -150,6 +159,11 @@ o_1_space_serial_transformation value =
150 [ bgroup "serially"
159 [ bgroup "serially"
151 [ bgroup "transformation"
160 [ bgroup "transformation"
152 [ benchIOSink value "lmap" (S.fold (IFL.lmap (+ 1) FL.drain))
161 [ benchIOSink value "lmap" (S.fold (IFL.lmap (+ 1) FL.drain))
162+ , benchIOSink
163+ value
164+ "sequence"
165+ (S.fold (FL.sequence (return <$> FL.drain)))
166+ , benchIOSink value "mapM" (S.fold (FL.mapM return FL.drain))
153 , benchIOSink
167 , benchIOSink
154 value
168 value
155 "pipe-mapM"
169 "pipe-mapM"
@@ -175,6 +189,24 @@ o_1_space_serial_composition value =
175 value
189 value
176 "sum,length"
190 "sum,length"
177 (S.fold ((,) <$> FL.sum <*> FL.length))
191 (S.fold ((,) <$> FL.sum <*> FL.length))
192+ , benchIOSink
193+ value
194+ "tee sum length"
195+ (S.fold (FL.tee FL.sum FL.length))
196+ , benchIOSink
197+ value
198+ "distribute sum length"
199+ (S.fold (FL.distribute [FL.sum, FL.length]))
200+ , benchIOSink
201+ value
202+ "partition sum length"
203+ (S.fold (IFL.lmap
204+ (\a -> if odd a then Left a else Right a)
205+ (FL.partition FL.sum FL.length)))
206+ , benchIOSink
207+ value
208+ "unzip sum length"
209+ (S.fold (IFL.lmap (\a -> (a, a)) (FL.unzip FL.sum FL.length)))
178 ]
210 ]
179 ]
211 ]
180 ]
212 ]