on a3203ff help sign in
93 lines 2.5 kB history raw
1{-# LANGUAGE CPP #-}
3#include "Streamly/Benchmark/Data/Array/CommonImports.hs"
5import Control.DeepSeq (deepseq)
7import qualified Streamly.Internal.Data.SmallArray as A
8type Stream = A.SmallArray
10#include "Streamly/Benchmark/Data/Array/Common.hs"
12-------------------------------------------------------------------------------
13-- Benchmark helpers
14-------------------------------------------------------------------------------
16-- Drain a source that generates an array in the IO monad
17{-# INLINE benchIOSrc #-}
18benchIOSrc :: NFData a => String -> (Int -> IO (Stream a)) -> Benchmark
19benchIOSrc name src = benchIO name src id
21-------------------------------------------------------------------------------
22-- Bench Ops
23-------------------------------------------------------------------------------
25{-# INLINE sourceIntFromToFromList #-}
26sourceIntFromToFromList :: MonadIO m => Int -> Int -> m (Stream Int)
27sourceIntFromToFromList value n = P.return $ A.fromListN value [n..n + value]
29{-# INLINE readInstance #-}
30readInstance :: P.String -> Stream Int
31readInstance str =
32 let r = P.reads str
33 in case r of
34 [(x,"")] -> x
35 _ -> P.error "readInstance: no parse"
37#ifdef DEVBUILD
38{-
39{-# INLINE foldableFoldl' #-}
40foldableFoldl' :: Stream Int -> Int
41foldableFoldl' = F.foldl' (+) 0
43{-# INLINE foldableSum #-}
44foldableSum :: Stream Int -> Int
45foldableSum = P.sum
46-}
47#endif
49-------------------------------------------------------------------------------
50-- Bench groups
51-------------------------------------------------------------------------------
53o_1_space_generation :: Int -> [Benchmark]
54o_1_space_generation value =
55 [ bgroup
56 "generation"
57 [ let testStr =
58 "fromListN " ++
59 show (value + 1) ++
60 "[1" ++ concat (replicate value ",1") ++ "]"
61 in testStr `deepseq` bench "read" (nf readInstance testStr)
62 ]
63 ]
65{-
66o_1_space_elimination :: Int -> [Benchmark]
67o_1_space_elimination value =
68 [ bgroup "elimination"
69 [
70#ifdef DEVBUILD
71{-
72 benchPureSink value "foldable/foldl'" foldableFoldl'
73 , benchPureSink value "foldable/sum" foldableSum
74-}
75#endif
76 ]
77 ]
78-}
80moduleName :: String
81moduleName = "Data.SmallArray"
83defStreamSize :: Int
84defStreamSize = 128
86main :: IO ()
87main = runWithCLIOpts defStreamSize allBenchmarks
89 where
91 allBenchmarks size =
92 bgroup (o_1_space_prefix moduleName) (o_1_space_generation size)
93 : commonBenchmarks size