on master help sign in
Merge O_n_Stack.hs into Prelude.hs
b62c02fadithyaov
benchmark/Streamly/Benchmark/Prelude/Serial/O_n_Stack.hs+8−52
@@ -5,42 +5,10 @@
5-- License : BSD3
5-- License : BSD3
6-- Maintainer : streamly@composewell.com
6-- Maintainer : streamly@composewell.com
7
7
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
15import Streamly.Benchmark.Common
8import Streamly.Benchmark.Common
9+import Streamly.Benchmark.Prelude
16
10
17−-------------------------------------------------------------------------------
11+import Gauge
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−-------------------------------------------------------------------------------
44
12
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 ()
49main = do
17main = do
50 (value, cfg, benches) <- parseCLIOpts defaultStreamSize
18 (value, cfg, benches) <- parseCLIOpts defaultStreamSize
51 size <- limitStreamSize value
19 size <- limitStreamSize value
52−
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`
22+ runMode
23+ (mode cfg)
24+ cfg
25+ benches
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)
67−
68− , benchIOSink size "tail" Ops.tail
69− , benchIOSink size "nullHeadTail" Ops.nullHeadTail
70− ]
71− ]
benchmark/lib/Streamly/Benchmark/Prelude.hs+27
@@ -2165,3 +2165,30 @@ o_n_heap_serial_buffering value =
2165 ]
2165 ]
2166 ]
2166 ]
2167 ]
2167 ]
2168+
2169+-- Head recursive operations.
2170+o_n_stack_serial_iterated :: Int -> [Benchmark]
2171+o_n_stack_serial_iterated value =
2172+ [ bgroup
2173+ "serially"
2174+ [ bgroup
2175+ "iterated"
2176+ [ benchIOSrc serially "mapMx10K" iterateMapM
2177+ , benchIOSrc serially "scanx100" iterateScan
2178+ , benchIOSrc serially "scanl1x100" iterateScanl1
2179+ , benchIOSrc serially "filterEvenx10K" iterateFilterEven
2180+ , benchIOSrc serially "takeAllx10K" (iterateTakeAll value)
2181+ , benchIOSrc serially "dropOnex10K" iterateDropOne
2182+ , benchIOSrc
2183+ serially
2184+ "dropWhileFalsex10K"
2185+ (iterateDropWhileFalse value)
2186+ , benchIOSrc
2187+ serially
2188+ "dropWhileTruex10K"
2189+ (iterateDropWhileTrue value)
2190+ , benchIOSink value "tail" tail
2191+ , benchIOSink value "nullHeadTail" nullHeadTail
2192+ ]
2193+ ]
2194+ ]