3#include "Streamly/Benchmark/Data/Array/CommonImports.hs"
5import Control.DeepSeq (deepseq)
7import qualified Streamly.Internal.Data.Array.Foreign as IA
8import qualified GHC.Exts as GHC
10import qualified Streamly.Data.Array.Foreign as A
11import qualified Streamly.Internal.Data.Array.Foreign as A
14#include "Streamly/Benchmark/Data/Array/Common.hs"
16-------------------------------------------------------------------------------
18-------------------------------------------------------------------------------
20-- Drain a source that generates a pure array
21{-# INLINE benchPureSrc #-}
22benchPureSrc :: String -> (Int -> Stream a) -> Benchmark
23benchPureSrc name src = benchPure name src id
25-- Drain a source that generates an array in the IO monad
26{-# INLINE benchIOSrc #-}
27benchIOSrc :: String -> (Int -> IO (Stream a)) -> Benchmark
28benchIOSrc name src = benchIO name src id
30-------------------------------------------------------------------------------
32-------------------------------------------------------------------------------
34{-# INLINE sourceIntFromToFromList #-}
35sourceIntFromToFromList :: MonadIO m => Int -> Int -> m (Stream Int)
36sourceIntFromToFromList value n = P.return $ A.fromListN value [n..n + value]
38{-# INLINE readInstance #-}
39readInstance :: P.String -> Stream Int
44 _ -> P.error "readInstance: no parse"
48{-# INLINE foldableFoldl' #-}
49foldableFoldl' :: Stream Int -> Int
50foldableFoldl' = F.foldl' (+) 0
52{-# INLINE foldableSum #-}
53foldableSum :: Stream Int -> Int
58{-# INLINE sourceIsList #-}
59sourceIsList :: Int -> Int -> Stream Int
60sourceIsList value n = GHC.fromList [n..n+value]
62{-# INLINE sourceIsString #-}
63sourceIsString :: Int -> Int -> Stream P.Char
64sourceIsString value n = GHC.fromString (P.replicate (n + value) 'a')
66{-# INLINE sourceIntFromToFromStream #-}
67sourceIntFromToFromStream :: MonadIO m => Int -> Int -> m (Stream Int)
68sourceIntFromToFromStream value n = S.fold A.write $ S.enumerateFromTo n (n + value)
70-------------------------------------------------------------------------------
72-------------------------------------------------------------------------------
74o_1_space_generation :: Int -> [Benchmark]
75o_1_space_generation value =
78 [ benchIOSrc "write . intFromTo" (sourceIntFromToFromStream value)
79 , let testStr = mkListString value
80 in testStr `deepseq` bench "read" (nf readInstance testStr)
81 , benchPureSrc "writeN . IsList.fromList" (sourceIsList value)
83 "writeN . IsString.fromString"
84 (sourceIsString value)
89o_1_space_elimination :: Int -> [Benchmark]
90o_1_space_elimination value =
91 [ bgroup "elimination"
92 [ benchPureSink value "length . IsList.toList" (length . GHC.toList)
93 , benchFold "writeLastN.1"
94 (S.fold (IA.writeLastN 1)) (P.sourceUnfoldrM value)
95 , benchFold "writeLastN.10"
96 (S.fold (IA.writeLastN 10)) (P.sourceUnfoldrM value)
99 benchPureSink value "foldable/foldl'" foldableFoldl'
100 , benchPureSink value "foldable/sum" foldableSum
106o_n_heap_serial :: Int -> [Benchmark]
107o_n_heap_serial value =
108 [ bgroup "elimination"
110 -- Converting the stream to an array
111 benchFold "writeLastN.Max" (S.fold (IA.writeLastN (value + 1)))
112 (P.sourceUnfoldrM value)
117moduleName = "Data.Array.Foreign"
120defStreamSize = defaultStreamSize
123main = runWithCLIOpts defStreamSize allBenchmarks
128 [ bgroup (o_1_space_prefix moduleName) $
129 o_1_space_generation size ++ o_1_space_elimination size
130 , bgroup (o_n_space_prefix moduleName) $
132 ] ++ 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