on master help sign in
Add foldMany1 and arraysOf benchmarks
commitde31277c196e6b428067c0d7e61d24e6e1d3eb0f authorHarendra Kumar <harendra@composewell.com> dateThu 4 Feb 2021, 02:56 (6 years ago) parent4c4c20b
2 files changed+36−4
benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+27−4 src/Streamly/Internal/Data/Stream/IsStream/Nesting.hs+9
benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+27−4
@@ -314,6 +314,10 @@ foldManyChunksOfSum :: Int -> Handle -> IO Int
314314foldManyChunksOfSum n inh =
315315 S.length $ IP.foldMany (FL.takeLE n FL.sum) (S.unfold FH.read inh)
316316
317+foldMany1ChunksOfSum :: Int -> Handle -> IO Int
318+foldMany1ChunksOfSum n inh =
319+ S.length $ IP.foldMany1 (FL.takeLE n FL.sum) (S.unfold FH.read inh)
320+
317321parseManyChunksOfSum :: Int -> Handle -> IO Int
318322parseManyChunksOfSum n inh =
319323 S.length
@@ -327,7 +331,6 @@ parseManyChunksOfSum n inh =
327331chunksOf :: Int -> Handle -> IO Int
328332chunksOf n inh =
329333 -- writeNUnsafe gives 2.5x boost here over writeN.
330− -- XXX replace with S.arraysOf
331334 S.length $ S.chunksOf n (AT.writeNUnsafe n) (S.unfold FH.read inh)
332335
333336#ifdef INSPECTION
@@ -339,6 +342,10 @@ inspect $ 'chunksOf `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
339342inspect $ 'chunksOf `hasNoType` ''MA.ReadUState -- FH.read/A.read
340343#endif
341344
345+{-# INLINE arraysOf #-}
346+arraysOf :: Int -> Handle -> IO Int
347+arraysOf n inh = S.length $ IP.arraysOf n (S.unfold FH.read inh)
348+
342349o_1_space_reduce_read_grouped :: BenchEnv -> [Benchmark]
343350o_1_space_reduce_read_grouped env =
344351 [ bgroup "reduce/read/chunks"
@@ -358,6 +365,14 @@ o_1_space_reduce_read_grouped env =
358365 "S.foldMany (FL.take 1 FL.sum)"
359366 env
360367 $ \inh _ -> inline foldManyChunksOfSum 1 inh
368+ , mkBenchSmall
369+ ("S.foldMany1 (FL.take " ++ show (bigSize env) ++ " FL.sum)")
370+ env
371+ $ \inh _ -> noinline foldMany1ChunksOfSum (bigSize env) inh
372+ , mkBench
373+ "S.foldMany1 (FL.take 1 FL.sum)"
374+ env
375+ $ \inh _ -> inline foldMany1ChunksOfSum 1 inh
361376 , mkBenchSmall
362377 ("S.parseMany (FL.take " ++ show (bigSize env) ++ " FL.sum)")
363378 env
@@ -368,12 +383,20 @@ o_1_space_reduce_read_grouped env =
368383 $ \inh _ -> inline parseManyChunksOfSum 1 inh
369384
370385 -- folding chunks to arrays
371− , mkBenchSmall "S.arraysOf 1" env $ \inh _ ->
386+ , mkBenchSmall "S.chunksOf 1" env $ \inh _ ->
372387 chunksOf 1 inh
373− , mkBench "S.arraysOf 10" env $ \inh _ ->
388+ , mkBench "S.chunksOf 10" env $ \inh _ ->
374389 chunksOf 10 inh
375− , mkBench "S.arraysOf 1000" env $ \inh _ ->
390+ , mkBench "S.chunksOf 1000" env $ \inh _ ->
376391 chunksOf 1000 inh
392+
393+ -- arraysOf may use a different impl than chunksOf
394+ , mkBenchSmall "S.arraysOf 1" env $ \inh _ ->
395+ arraysOf 1 inh
396+ , mkBench "S.arraysOf 10" env $ \inh _ ->
397+ arraysOf 10 inh
398+ , mkBench "S.arraysOf 1000" env $ \inh _ ->
399+ arraysOf 1000 inh
377400 ]
378401 ]
379402
src/Streamly/Internal/Data/Stream/IsStream/Nesting.hs+9
@@ -127,6 +127,7 @@ module Streamly.Internal.Data.Stream.IsStream.Nesting
127127 -- ** Folding
128128 -- | Apply folds on a stream.
129129 , foldMany
130+ , foldMany1
130131 , foldSequence
131132 , foldIterate
132133
@@ -926,6 +927,14 @@ foldMany
926927 -> t m b
927928foldMany f m = D.fromStreamD $ D.foldMany f (D.toStreamD m)
928929
930+{-# INLINE foldMany1 #-}
931+foldMany1
932+ :: (IsStream t, Monad m)
933+ => Fold m a b
934+ -> t m a
935+ -> t m b
936+foldMany1 f m = D.fromStreamD $ D.foldMany1 f (D.toStreamD m)
937+
929938-- | Apply a stream of folds to an input stream and emit the results in the
930939-- output stream.
931940--