3#include "Streamly/Benchmark/Data/Array/CommonImports.hs"
5import Control.DeepSeq (deepseq)
7import qualified Streamly.Internal.Data.Array as IA
8import qualified Streamly.Internal.Data.Array as A
11#include "Streamly/Benchmark/Data/Array/Common.hs"
13-------------------------------------------------------------------------------
15-------------------------------------------------------------------------------
17-- Drain a source that generates an array in the IO monad
18{-# INLINE benchIOSrc #-}
19benchIOSrc :: NFData a => String -> (Int -> IO (Stream a)) -> Benchmark
20benchIOSrc name src = benchIO name src id
22-------------------------------------------------------------------------------
24-------------------------------------------------------------------------------
26{-# INLINE sourceIntFromToFromList #-}
27sourceIntFromToFromList :: MonadIO m => Int -> Int -> m (Stream Int)
28sourceIntFromToFromList value n = P.return $ A.fromListN value [n..n + value]
31{-# INLINE readInstance #-}
32readInstance :: P.String -> Stream Int
37 _ -> P.error "readInstance: no parse"
41{-# INLINE foldableFoldl' #-}
42foldableFoldl' :: Stream Int -> Int
43foldableFoldl' = F.foldl' (+) 0
45{-# INLINE foldableSum #-}
46foldableSum :: Stream Int -> Int
51{-# INLINE sourceIntFromToFromStream #-}
52sourceIntFromToFromStream :: MonadIO m => Int -> Int -> m (Stream Int)
53sourceIntFromToFromStream value n = S.fold A.write $ S.enumerateFromTo n (n + value)
55-------------------------------------------------------------------------------
57-------------------------------------------------------------------------------
59o_1_space_generation :: Int -> [Benchmark]
60o_1_space_generation value =
63 [ benchIOSrc "write . intFromTo" (sourceIntFromToFromStream value)
64 , let testStr = mkListString value
65 in testStr `deepseq` bench "read" (nf readInstance testStr)
69o_1_space_elimination :: Int -> [Benchmark]
70o_1_space_elimination value =
71 [ bgroup "elimination"
72 [ benchFold "writeLastN.1"
73 (S.fold (IA.writeLastN 1)) (P.sourceUnfoldrM value)
74 , benchFold "writeLastN.10"
75 (S.fold (IA.writeLastN 10)) (P.sourceUnfoldrM value)
78 benchPureSink value "foldable/foldl'" foldableFoldl'
79 , benchPureSink value "foldable/sum" foldableSum
85o_n_heap_serial :: Int -> [Benchmark]
86o_n_heap_serial value =
87 [ bgroup "elimination"
89 -- Converting the stream to an array
90 benchFold "writeLastN.Max" (S.fold (IA.writeLastN (value + 1)))
91 (P.sourceUnfoldrM value)
96moduleName = "Data.Array"
99defStreamSize = defaultStreamSize
102main = runWithCLIOpts defStreamSize allBenchmarks
107 [ bgroup (o_1_space_prefix moduleName) $
108 o_1_space_generation size ++ o_1_space_elimination size
109 , bgroup (o_n_space_prefix moduleName) $
111 ] ++ commonBenchmarks size
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list