on master help sign in
Add micro benchmarks for convering exposed APIs in Fold

Benchamrks added: - drainBy - foldMapM - lookup - sequence - tee - distribute - partition - unzip

commitfc25c42ab1dceef478d44aa399542031d716b311 authoradithyaov <adi.obilisetty@gmail.com> dateTue 11 Aug 2020, 03:19 (6 years ago) parentcd40d90
1 file changed+33−1
benchmark/Streamly/Benchmark/Data/Fold.hs+33−1
benchmark/Streamly/Benchmark/Data/Fold.hs+33−1
@@ -15,7 +15,7 @@ import Data.Monoid (Last(..), Sum(..))
1515import System.Random (randomRIO)
1616import Prelude (IO, Int, Double, String, (>), (<*>), (<$>), (+), ($),
1717 (<=), Monad(..), (==), Maybe(..), (.), fromIntegral,
18− compare, (>=), concat, seq)
18+ compare, (>=), concat, seq, Either(..), odd)
1919
2020import qualified Streamly.Prelude as S
2121import qualified Streamly.Internal.Data.Fold as FL
@@ -66,6 +66,7 @@ o_1_space_serial_elimination value =
6666 [ bgroup "serially"
6767 [ bgroup "elimination"
6868 [ benchIOSink value "drain" (S.fold FL.drain)
69+ , benchIOSink value "drainBy" (S.fold (FL.drainBy return))
6970 , benchIOSink value "drainN" (S.fold (IFL.drainN value))
7071 , benchIOSink
7172 value
@@ -116,9 +117,17 @@ o_1_space_serial_elimination value =
116117 value
117118 "foldMap"
118119 (S.fold (FL.foldMap (Last . Just)))
120+ , benchIOSink
121+ value
122+ "foldMapM"
123+ (S.fold (FL.foldMapM (return . Last . Just)))
119124 , benchIOSink value "index" (S.fold (FL.index (value + 1)))
120125 , benchIOSink value "head" (S.fold FL.head)
121126 , 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))))
122131 , benchIOSink
123132 value
124133 "findIndex"
@@ -150,6 +159,11 @@ o_1_space_serial_transformation value =
150159 [ bgroup "serially"
151160 [ bgroup "transformation"
152161 [ 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))
153167 , benchIOSink
154168 value
155169 "pipe-mapM"
@@ -175,6 +189,24 @@ o_1_space_serial_composition value =
175189 value
176190 "sum,length"
177191 (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)))
178210 ]
179211 ]
180212 ]