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.Generic as IA
11import qualified Streamly.Internal.Data.Array.Generic as A
15#include "Streamly/Benchmark/Data/Array/Common.hs"
17instance NFData a => NFData (A.Array a) where
19 rnf = A.foldl' (\_ x -> rnf x) ()
21-------------------------------------------------------------------------------
23-------------------------------------------------------------------------------
25-- Drain a source that generates an array in the IO monad
26{-# INLINE benchIOSrc #-}
27benchIOSrc :: NFData a => 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 sourceIntFromToFromStream #-}
59sourceIntFromToFromStream :: MonadIO m => Int -> Int -> m (Stream Int)
60sourceIntFromToFromStream value n =
61 S.fold A.write $ S.enumerateFromTo n (n + value)
63-------------------------------------------------------------------------------
65-------------------------------------------------------------------------------
67o_1_space_generation :: Int -> [Benchmark]
68o_1_space_generation value =
71 [ benchIOSrc "write . intFromTo" (sourceIntFromToFromStream value)
72 , let testStr = "fromList " ++ mkListString value
73 in testStr `deepseq` bench "read" (nf readInstance testStr)
77o_1_space_elimination :: Int -> [Benchmark]
78o_1_space_elimination value =
79 [ bgroup "elimination"
80 [ benchFold "writeLastN.1"
81 (S.fold (IA.writeLastN 1)) (P.sourceUnfoldrM value)
82 , benchFold "writeLastN.10"
83 (S.fold (IA.writeLastN 10)) (P.sourceUnfoldrM value)
86 benchPureSink value "foldable/foldl'" foldableFoldl'
87 , benchPureSink value "foldable/sum" foldableSum
93o_n_heap_serial :: Int -> [Benchmark]
94o_n_heap_serial value =
95 [ bgroup "elimination"
97 -- Converting the stream to an array
98 benchFold "writeLastN.Max" (S.fold (IA.writeLastN (value + 1)))
99 (P.sourceUnfoldrM value)
104moduleName = "Data.Array.Generic"
107defStreamSize = defaultStreamSize
110main = runWithCLIOpts defStreamSize allBenchmarks
115 [ bgroup (o_1_space_prefix moduleName) $
116 o_1_space_generation size ++ o_1_space_elimination size
117 , bgroup (o_n_space_prefix moduleName) $
119 ] ++ 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