@@ -5,42 +5,10 @@
55-- License : BSD3
66-- Maintainer : streamly@composewell.com
77
8−import Control.DeepSeq (NFData(..))
9−import System.Random (randomRIO)
10−
11−import qualified Streamly.Benchmark.Prelude as Ops
12−
13−import Streamly
14−import Gauge
158import Streamly.Benchmark.Common
9+import Streamly.Benchmark.Prelude
1610
17−-------------------------------------------------------------------------------
18−--
19−-------------------------------------------------------------------------------
20−
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.
23−
24−-- | Takes a fold method, and uses it with a default source.
25−{-# INLINE benchIOSink #-}
26−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
30−
31−-- | Takes a source, and uses it with a default drain/fold method.
32−{-# INLINE benchIOSrc #-}
33−benchIOSrc
34− :: (t IO a -> SerialT IO a)
35− -> String
36− -> (Int -> t IO a)
37− -> Benchmark
38−benchIOSrc t name f =
39− bench name $ nfIO $ randomRIO (1,1) >>= Ops.toNull t . f
40−
41−-------------------------------------------------------------------------------
42−--
43−-------------------------------------------------------------------------------
11+import Gauge
4412
4513-- In addition to gauge options, the number of elements in the stream can be
4614-- passed using the --stream-size option.
@@ -49,23 +17,11 @@ main :: IO ()
4917main = do
5018 (value, cfg, benches) <- parseCLIOpts defaultStreamSize
5119 size <- limitStreamSize value
52−
5320 -- Operations using O(n) stack space but O(1) heap space.
54− size `seq` runMode (mode cfg) cfg benches
21+ size `seq`
22+ runMode
23+ (mode cfg)
24+ cfg
25+ benches
5526 -- Head recursive operations.
56− [ bgroup "iterated"
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)
67−
68− , benchIOSink size "tail" Ops.tail
69− , benchIOSink size "nullHeadTail" Ops.nullHeadTail
70− ]
71− ]
27+ (o_n_stack_serial_iterated size)