on master help sign in
Move the concat benchmark to Unfold module

Remove the NestedUnfoldOps module.

commite6865109d1613d82f29b882a366c9a9ba22139f9 authorHarendra Kumar <harendra@composewell.com> dateSat 20 Feb 2021, 10:38 (6 years ago) parentb47918e
3 files changed+36−52
benchmark/Streamly/Benchmark/Data/NestedUnfoldOps.hs−40 benchmark/Streamly/Benchmark/Data/Unfold.hs+36−11 benchmark/streamly-benchmarks.cabal−1
benchmark/Streamly/Benchmark/Data/NestedUnfoldOps.hsdeleted−40
@@ -1,40 +0,0 @@
1−-- |
2−-- Module : NestedUnfoldOps
3−-- Copyright : (c) 2019 Composewell Technologies
4−--
5−-- License : BSD3
6−-- Maintainer : streamly@composewell.com
7−
8−module Streamly.Benchmark.Data.NestedUnfoldOps where
9−
10−import Control.Monad.IO.Class (MonadIO (..))
11−import Streamly.Internal.Data.Unfold (Unfold)
12−
13−import qualified Streamly.Internal.Data.Unfold as UF
14−import qualified Streamly.Internal.Data.Fold as FL
15−
16−-- n * (n + 1) / 2 == linearCount
17−concatCount :: Int -> Int
18−concatCount linearCount =
19− round (((1 + 8 * fromIntegral linearCount)**(1/2::Double) - 1) / 2)
20−
21−-------------------------------------------------------------------------------
22−-- Stream generation and elimination
23−-------------------------------------------------------------------------------
24−
25−-- generate numbers up to the argument value
26−{-# INLINE source #-}
27−source :: Monad m => Int -> Unfold m Int Int
28−source n = UF.enumerateFromToIntegral n
29−
30−-------------------------------------------------------------------------------
31−-- Benchmark ops
32−-------------------------------------------------------------------------------
33−
34−{-# INLINE concat #-}
35−concat :: MonadIO m => Int -> Int -> m ()
36−concat linearCount start = do
37− let end = start + concatCount linearCount
38− UF.fold
39− (UF.concat (source end) (source end))
40− FL.drain start
benchmark/Streamly/Benchmark/Data/Unfold.hs+36−11
@@ -26,7 +26,6 @@ import System.IO (Handle, hClose)
2626import System.Random (randomRIO)
2727
2828import qualified Prelude
29−import qualified Streamly.Benchmark.Data.NestedUnfoldOps as Nested
3029import qualified Streamly.FileSystem.Handle as FH
3130import qualified Streamly.Internal.Data.Fold as FL
3231import qualified Streamly.Internal.Data.Unfold as UF
@@ -48,6 +47,15 @@ import Test.Inspection
4847benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
4948benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
5049
50+-------------------------------------------------------------------------------
51+-- Stream generation and elimination
52+-------------------------------------------------------------------------------
53+
54+-- generate numbers up to the argument value
55+{-# INLINE source #-}
56+source :: Monad m => Int -> Unfold m Int Int
57+source n = UF.enumerateFromToIntegral n
58+
5159-------------------------------------------------------------------------------
5260-- Benchmark helpers
5361-------------------------------------------------------------------------------
@@ -404,7 +412,7 @@ teeZipWith size start =
404412toNullAp :: Monad m => Int -> Int -> m ()
405413toNullAp value start =
406414 let end = start + nthRoot 2 value
407− s = Nested.source end
415+ s = source end
408416 in UF.fold ((+) <$> s <*> s) FL.drain start
409417
410418{-# INLINE _apDiscardFst #-}
@@ -437,7 +445,7 @@ concatMapM value start =
437445toNull :: Monad m => Int -> Int -> m ()
438446toNull value start =
439447 let end = start + nthRoot 2 value
440− src = Nested.source end
448+ src = source end
441449 u = do
442450 x <- src
443451 y <- src
@@ -449,7 +457,7 @@ toNull value start =
449457toNull3 :: Monad m => Int -> Int -> m ()
450458toNull3 value start =
451459 let end = start + nthRoot 3 value
452− src = Nested.source end
460+ src = source end
453461 u = do
454462 x <- src
455463 y <- src
@@ -461,7 +469,7 @@ toNull3 value start =
461469toList :: Monad m => Int -> Int -> m [Int]
462470toList value start = do
463471 let end = start + nthRoot 2 value
464− src = Nested.source end
472+ src = source end
465473 u = do
466474 x <- src
467475 y <- src
@@ -472,7 +480,7 @@ toList value start = do
472480toListSome :: Monad m => Int -> Int -> m [Int]
473481toListSome value start = do
474482 let end = start + nthRoot 2 value
475− src = Nested.source end
483+ src = source end
476484 u = do
477485 x <- src
478486 y <- src
@@ -483,7 +491,7 @@ toListSome value start = do
483491filterAllOut :: Monad m => Int -> Int -> m ()
484492filterAllOut value start = do
485493 let end = start + nthRoot 2 value
486− src = Nested.source end
494+ src = source end
487495 u = do
488496 x <- src
489497 y <- src
@@ -497,7 +505,7 @@ filterAllOut value start = do
497505filterAllIn :: Monad m => Int -> Int -> m ()
498506filterAllIn value start = do
499507 let end = start + nthRoot 2 value
500− src = Nested.source end
508+ src = source end
501509 u = do
502510 x <- src
503511 y <- src
@@ -511,7 +519,7 @@ filterAllIn value start = do
511519filterSome :: Monad m => Int -> Int -> m ()
512520filterSome value start = do
513521 let end = start + nthRoot 2 value
514− src = Nested.source end
522+ src = source end
515523 u = do
516524 x <- src
517525 y <- src
@@ -525,7 +533,7 @@ filterSome value start = do
525533breakAfterSome :: Int -> Int -> IO ()
526534breakAfterSome value start =
527535 let end = start + nthRoot 2 value
528− src = Nested.source end
536+ src = source end
529537 u = do
530538 x <- src
531539 y <- src
@@ -537,6 +545,23 @@ breakAfterSome value start =
537545 (_ :: Either ErrorCall ()) <- try $ UF.fold u FL.drain start
538546 return ()
539547
548+-------------------------------------------------------------------------------
549+-- Benchmark ops
550+-------------------------------------------------------------------------------
551+
552+-- n * (n + 1) / 2 == linearCount
553+concatCount :: Int -> Int
554+concatCount linearCount =
555+ round (((1 + 8 * fromIntegral linearCount)**(1/2::Double) - 1) / 2)
556+
557+{-# INLINE concat #-}
558+concat :: Monad m => Int -> Int -> m ()
559+concat linearCount start = do
560+ let end = start + concatCount linearCount
561+ UF.fold
562+ (UF.concat (source end) (source end))
563+ FL.drain start
564+
540565-------------------------------------------------------------------------------
541566-- Benchmarks
542567-------------------------------------------------------------------------------
@@ -649,7 +674,7 @@ o_1_space_nested size =
649674 , benchIO "filterAllIn" $ filterAllIn size
650675 , benchIO "filterSome" $ filterSome size
651676
652− , benchIO "concat" $ Nested.concat size
677+ , benchIO "concat" $ concat size
653678 ]
654679 ]
655680
benchmark/streamly-benchmarks.cabal−1
@@ -256,7 +256,6 @@ benchmark Data.Unfold
256256 type: exitcode-stdio-1.0
257257 hs-source-dirs: .
258258 main-is: Streamly/Benchmark/Data/Unfold.hs
259− other-modules: Streamly.Benchmark.Data.NestedUnfoldOps
260259 if impl(ghcjs)
261260 buildable: False
262261 else