@@ -5,105 +5,23 @@
55-- License : BSD3
66-- Maintainer : streamly@composewell.com
77
8−import Control.DeepSeq (NFData(..))
9−import Data.Functor.Identity (Identity)
10−import System.Random (randomRIO)
11−
12−import qualified Streamly.Benchmark.Prelude as Ops
13−
14−import qualified Streamly.Data.Fold as FL
15−import qualified Streamly.Memory.Array as A
16−import qualified Streamly.Prelude as S
17−
18−import qualified Streamly.Internal.Data.Fold as IFL
19−import qualified Streamly.Internal.Memory.Array as IA
20−import qualified Streamly.Internal.Prelude as IP
21−
22−import Gauge
23−import Streamly
248import Streamly.Benchmark.Common
9+import Streamly.Benchmark.Prelude
2510
26−-------------------------------------------------------------------------------
27−--
28−-------------------------------------------------------------------------------
29−
30−-- We need a monadic bind here to make sure that the function f does not get
31−-- completely optimized out by the compiler in some cases.
32−
33−-- | Takes a fold method, and uses it with a default source.
34−{-# INLINE benchIOSink #-}
35−benchIOSink
36− :: (IsStream t, NFData b)
37− => Int -> String -> (t IO Int -> IO b) -> Benchmark
38−benchIOSink value name f =
39− bench name $ nfIO $ randomRIO (1,1) >>= f . Ops.source value
40−
41−-- XXX We should be using sourceUnfoldrM for fair comparison with IO monad, but
42−-- we can't use it as it requires MonadAsync constraint.
43−{-# INLINE benchIdentitySink #-}
44−benchIdentitySink
45− :: (IsStream t, NFData b)
46− => Int -> String -> (t Identity Int -> Identity b) -> Benchmark
47−benchIdentitySink value name f = bench name $ nf (f . Ops.sourceUnfoldr value) 1
48−
49−-------------------------------------------------------------------------------
50−--
51−-------------------------------------------------------------------------------
11+import Gauge
5212
5313-- In addition to gauge options, the number of elements in the stream can be
5414-- passed using the --stream-size option.
5515--
5616main :: IO ()
5717main = do
58− -- XXX Fix indentation
5918 (value, cfg, benches) <- parseCLIOpts defaultStreamSize
6019 size <- limitStreamSize value
61−
62− size `seq` runMode (mode cfg) cfg benches
20+ size `seq`
21+ runMode
22+ (mode cfg)
23+ cfg
24+ benches
6325 -- Operations using O(1) stack space and O(n) heap space.
6426 -- Tail recursive left folds
65− [ bgroup "foldl"
66− [
67− -- Left folds for building a structure are inherently non-streaming
68− -- as the structure cannot be lazily consumed until fully built.
69− benchIOSink size "foldl'/build/IO" Ops.foldl'Build
70− , benchIdentitySink size "foldl'/build/Identity" Ops.foldl'Build
71− , benchIOSink size "foldlM'/build/IO" Ops.foldlM'Build
72− , benchIdentitySink size "foldlM'/build/Identity" Ops.foldlM'Build
73−
74− , benchIOSink size "toStream" (S.fold IP.toStream)
75− , benchIOSink size "toStreamRev" (S.fold IP.toStreamRev)
76−
77− , benchIOSink size "toList" (S.fold FL.toList)
78− , benchIOSink size "toListRevF" (S.fold IFL.toListRevF)
79−
80− -- Converting the stream to an array
81− , benchIOSink size "lastN.Max" (S.fold (IA.lastN (size + 1)))
82− , benchIOSink size "writeN" (S.fold (A.writeN size))
83−
84− -- Reversing/sorting a stream
85− , benchIOSink size "reverse" (Ops.reverse 1)
86− , benchIOSink size "reverse'" (Ops.reverse' 1)
87− ]
88− , bgroup "buffering"
89− [
90− -- Buffers the output of show/read.
91− -- XXX can the outputs be streaming? Can we have special read/show
92− -- style type classes, readM/showM supporting streaming effects?
93− bench "readsPrec pure streams" $
94− nf Ops.readInstance (mkString size)
95− , bench "readsPrec Haskell lists" $
96− nf Ops.readInstanceList (mkListString size)
97− , bench "showPrec Haskell lists" $
98− nf Ops.showInstanceList (mkList size)
99−
100− -- interleave x/4 streams of 4 elements each. Needs to buffer
101− -- proportional to x/4. This is different from WSerial because
102− -- WSerial expands slowly because of binary interleave behavior and
103− -- this expands immediately because of Nary interleave behavior.
104− , benchIOSrc1 "concatUnfoldInterleaveRepl (x/4,4)"
105− (Ops.concatUnfoldInterleaveRepl4xN size)
106− , benchIOSrc1 "concatUnfoldRoundrobinRepl (x/4,4)"
107− (Ops.concatUnfoldRoundrobinRepl4xN size)
108− ]
109− ]
27+ (concat [o_n_heap_serial_foldl size, o_n_heap_serial_buffering size])