1{-# OPTIONS_GHC -Wno-deprecations #-}
2{-# OPTIONS_GHC -Wno-orphans #-}
6#include "Streamly/Benchmark/Data/Array/CommonImports.hs"
8import Control.DeepSeq (deepseq)
10import qualified Streamly.Internal.Data.Array as IA
11import qualified GHC.Exts as GHC
13-- import qualified Streamly.Data.Array as A
14import qualified Streamly.Internal.Data.Array as A
18#include "Streamly/Benchmark/Data/Array/Common.hs"
20instance NFData (A.Array a) where
24-------------------------------------------------------------------------------
26-------------------------------------------------------------------------------
28-- Drain a source that generates a pure array
29{-# INLINE benchPureSrc #-}
30benchPureSrc :: String -> (Int -> Stream a) -> Benchmark
31benchPureSrc name src = benchPure name src id
33-- Drain a source that generates an array in the IO monad
34{-# INLINE benchIOSrc #-}
35benchIOSrc :: String -> (Int -> IO (Stream a)) -> Benchmark
36benchIOSrc name src = benchIO name src id
38-------------------------------------------------------------------------------
40-------------------------------------------------------------------------------
42{-# INLINE sourceIntFromToFromList #-}
43sourceIntFromToFromList :: MonadIO m => Int -> Int -> m (Stream Int)
44sourceIntFromToFromList value n = P.return $ A.fromListN value [n..n + value]
46{-# INLINE readInstance #-}
47readInstance :: P.String -> Stream Int
52 _ -> P.error "readInstance: no parse"
56{-# INLINE foldableFoldl' #-}
57foldableFoldl' :: Stream Int -> Int
58foldableFoldl' = F.foldl' (+) 0
60{-# INLINE foldableSum #-}
61foldableSum :: Stream Int -> Int
66{-# INLINE sourceIsList #-}
67sourceIsList :: Int -> Int -> Stream Int
68sourceIsList value n = GHC.fromList [n..n+value]
70{-# INLINE sourceIsString #-}
71sourceIsString :: Int -> Int -> Stream P.Char
72sourceIsString value n = GHC.fromString (P.replicate (n + value) 'a')
74{-# INLINE sourceIntFromToFromStream #-}
75sourceIntFromToFromStream :: MonadIO m => Int -> Int -> m (Stream Int)
76sourceIntFromToFromStream value n = S.fold A.write $ S.enumerateFromTo n (n + value)
78-------------------------------------------------------------------------------
80-------------------------------------------------------------------------------
82o_1_space_generation :: Int -> [Benchmark]
83o_1_space_generation value =
86 [ benchIOSrc "write . intFromTo" (sourceIntFromToFromStream value)
87 , let testStr = "fromList " ++ mkListString value
88 in testStr `deepseq` bench "read" (nf readInstance testStr)
89 , benchPureSrc "writeN . IsList.fromList" (sourceIsList value)
91 "writeN . IsString.fromString"
92 (sourceIsString value)
97o_1_space_elimination :: Int -> [Benchmark]
98o_1_space_elimination value =
99 [ bgroup "elimination"
100 [ benchPureSink value "length . IsList.toList" (length . GHC.toList)
101 , benchFold "writeLastN.1"
102 (S.fold (IA.writeLastN 1)) (P.sourceUnfoldrM value)
103 , benchFold "writeLastN.10"
104 (S.fold (IA.writeLastN 10)) (P.sourceUnfoldrM value)
107 benchPureSink value "foldable/foldl'" foldableFoldl'
108 , benchPureSink value "foldable/sum" foldableSum
114o_n_heap_serial :: Int -> [Benchmark]
115o_n_heap_serial value =
116 [ bgroup "elimination"
118 -- Converting the stream to an array
119 benchFold "writeLastN.Max" (S.fold (IA.writeLastN (value + 1)))
120 (P.sourceUnfoldrM value)
125moduleName = "Data.Array"
128defStreamSize = defaultStreamSize
131main = runWithCLIOpts defStreamSize allBenchmarks
136 [ bgroup (o_1_space_prefix moduleName) $
137 o_1_space_generation size ++ o_1_space_elimination size
138 , bgroup (o_n_space_prefix moduleName) $
140 ] ++ 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