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