@@ -5,42 +5,10 @@
5-- License : BSD3
5-- License : BSD3
6-- Maintainer : streamly@composewell.com
6-- Maintainer : streamly@composewell.com
8−import Control.DeepSeq (NFData(..))
9−import System.Random (randomRIO)
11−import qualified Streamly.Benchmark.Prelude as Ops
15import Streamly.Benchmark.Common
8import Streamly.Benchmark.Common
9+import Streamly.Benchmark.Prelude
17−-------------------------------------------------------------------------------
11+import Gauge
19−-------------------------------------------------------------------------------
21−-- We need a monadic bind here to make sure that the function f does not get
22−-- completely optimized out by the compiler in some cases.
24−-- | Takes a fold method, and uses it with a default source.
25−{-# INLINE benchIOSink #-}
27− :: (IsStream t, NFData b)
28− => Int -> String -> (t IO Int -> IO b) -> Benchmark
29−benchIOSink value name f = bench name $ nfIO $ randomRIO (1,1) >>= f . Ops.source value
31−-- | Takes a source, and uses it with a default drain/fold method.
32−{-# INLINE benchIOSrc #-}
34− :: (t IO a -> SerialT IO a)
39− bench name $ nfIO $ randomRIO (1,1) >>= Ops.toNull t . f
41−-------------------------------------------------------------------------------
43−-------------------------------------------------------------------------------
45-- In addition to gauge options, the number of elements in the stream can be
13-- In addition to gauge options, the number of elements in the stream can be
46-- passed using the --stream-size option.
14-- passed using the --stream-size option.
@@ -49,23 +17,11 @@ main :: IO ()
50 (value, cfg, benches) <- parseCLIOpts defaultStreamSize
18 (value, cfg, benches) <- parseCLIOpts defaultStreamSize
51 size <- limitStreamSize value
19 size <- limitStreamSize value
53 -- Operations using O(n) stack space but O(1) heap space.
20 -- Operations using O(n) stack space but O(1) heap space.
54− size `seq` runMode (mode cfg) cfg benches
21+ size `seq`
55 -- Head recursive operations.
26 -- Head recursive operations.
56− [ bgroup "iterated"
27+ (o_n_stack_serial_iterated size)
57− [ benchIOSrc serially "mapMx10K" Ops.iterateMapM
58− , benchIOSrc serially "scanx100" Ops.iterateScan
59− , benchIOSrc serially "scanl1x100" Ops.iterateScanl1
60− , benchIOSrc serially "filterEvenx10K" Ops.iterateFilterEven
61− , benchIOSrc serially "takeAllx10K" (Ops.iterateTakeAll size)
62− , benchIOSrc serially "dropOnex10K" Ops.iterateDropOne
63− , benchIOSrc serially "dropWhileFalsex10K"
64− (Ops.iterateDropWhileFalse size)
65− , benchIOSrc serially "dropWhileTruex10K"
66− (Ops.iterateDropWhileTrue size)
68− , benchIOSink size "tail" Ops.tail
69− , benchIOSink size "nullHeadTail" Ops.nullHeadTail