on master help sign in
Move benchmarks of Array.Prim.Pinned out of common benchmark mess
f8d80ccadithyaov
benchmark/Streamly/Benchmark/Data/Array.hs+1−22
@@ -28,9 +28,7 @@ import Gauge
28import Streamly.Benchmark.Common hiding (benchPureSrc)
28import Streamly.Benchmark.Common hiding (benchPureSrc)
29import qualified Streamly.Benchmark.Prelude as P
29import qualified Streamly.Benchmark.Prelude as P
30
30
31−#if !defined(DATA_ARRAY_PRIM) && !defined(DATA_ARRAY_PRIM_PINNED)
32import Control.DeepSeq (deepseq)
31import Control.DeepSeq (deepseq)
33−#endif
34
32
35-------------------------------------------------------------------------------
33-------------------------------------------------------------------------------
36--
34--
@@ -43,11 +41,7 @@ benchIO name src f = bench name $ nfIO $
43
41
44-- Drain a source that generates an array in the IO monad
42-- Drain a source that generates an array in the IO monad
45{-# INLINE benchIOSrc #-}
43{-# INLINE benchIOSrc #-}
46−benchIOSrc ::
47−#if !defined(DATA_ARRAY_PRIM_PINNED)
48− NFData a =>
49−#endif
50− String -> (Int -> IO (Ops.Stream a)) -> Benchmark
44+benchIOSrc :: NFData a => String -> (Int -> IO (Ops.Stream a)) -> Benchmark
51benchIOSrc name src = benchIO name src id
45benchIOSrc name src = benchIO name src id
52
46
53{-# INLINE benchPureSink #-}
47{-# INLINE benchPureSink #-}
@@ -76,17 +70,8 @@ o_1_space_generation value =
76 (Ops.sourceIntFromToFromList value)
70 (Ops.sourceIntFromToFromList value)
77 , benchIOSrc "writeN . unfoldr" (Ops.sourceUnfoldr value)
71 , benchIOSrc "writeN . unfoldr" (Ops.sourceUnfoldr value)
78 , benchIOSrc "writeN . fromList" (Ops.sourceFromList value)
72 , benchIOSrc "writeN . fromList" (Ops.sourceFromList value)
79−#if !defined(DATA_ARRAY_PRIM_PINNED)
80−#ifdef DATA_SMALLARRAY
81− , let testStr =
82− "fromListN " ++
83− show (value + 1) ++
84− "[1" ++ concat (replicate value ",1") ++ "]"
85−#else
86 , let testStr = mkListString value
73 , let testStr = mkListString value
87−#endif
88 in testStr `deepseq` (bench "read" $ nf Ops.readInstance testStr)
74 in testStr `deepseq` (bench "read" $ nf Ops.readInstance testStr)
89−#endif
90 , benchPureSink value "show" Ops.showInstance
75 , benchPureSink value "show" Ops.showInstance
91 ]
76 ]
92 ]
77 ]
@@ -106,13 +91,11 @@ o_1_space_elimination value =
106 (S.fold (IA.writeLastN 1)) (P.sourceUnfoldrM value)
91 (S.fold (IA.writeLastN 1)) (P.sourceUnfoldrM value)
107 , benchFold "writeLastN.10"
92 , benchFold "writeLastN.10"
108 (S.fold (IA.writeLastN 10)) (P.sourceUnfoldrM value)
93 (S.fold (IA.writeLastN 10)) (P.sourceUnfoldrM value)
109−#if !defined(DATA_ARRAY_PRIM) && !defined(DATA_ARRAY_PRIM_PINNED)
110#ifdef DEVBUILD
94#ifdef DEVBUILD
111{-
95{-
112 , benchPureSink value "foldable/foldl'" Ops.foldableFoldl'
96 , benchPureSink value "foldable/foldl'" Ops.foldableFoldl'
113 , benchPureSink value "foldable/sum" Ops.foldableSum
97 , benchPureSink value "foldable/sum" Ops.foldableSum
114-}
98-}
115−#endif
116#endif
99#endif
117 ]
100 ]
118 ]
101 ]
@@ -148,11 +131,7 @@ o_1_space_transformationX4 value =
148 ]
131 ]
149
132
150moduleName :: String
133moduleName :: String
151−#if defined(DATA_ARRAY_PRIM_PINNED)
152−moduleName = "Data.Array.Prim.Pinned"
153−#else
154moduleName = "Data.Array"
134moduleName = "Data.Array"
155−#endif
156
135
157defStreamSize :: Int
136defStreamSize :: Int
158defStreamSize = defaultStreamSize
137defStreamSize = defaultStreamSize
benchmark/Streamly/Benchmark/Data/Array/Prim/Pinned.hsnew file+58
@@ -0,0 +1,58 @@
1+{-# LANGUAGE CPP #-}
2+
3+#include "Streamly/Benchmark/Data/Array/CommonImports.hs"
4+
5+import qualified Streamly.Internal.Data.Array.Prim.Pinned as A
6+type Stream = A.Array
7+
8+#include "Streamly/Benchmark/Data/Array/Common.hs"
9+
10+-------------------------------------------------------------------------------
11+-- Benchmark helpers
12+-------------------------------------------------------------------------------
13+
14+-- Drain a source that generates an array in the IO monad
15+{-# INLINE benchIOSrc #-}
16+benchIOSrc :: String -> (Int -> IO (Stream a)) -> Benchmark
17+benchIOSrc name src = benchIO name src id
18+
19+-------------------------------------------------------------------------------
20+-- Bench Ops
21+-------------------------------------------------------------------------------
22+
23+{-# INLINE sourceIntFromToFromList #-}
24+sourceIntFromToFromList :: MonadIO m => Int -> Int -> m (Stream Int)
25+sourceIntFromToFromList value n = P.return $ A.fromListN value $ [n..n + value]
26+
27+-- CPP:
28+{-# INLINE sourceIntFromToFromStream #-}
29+sourceIntFromToFromStream :: MonadIO m => Int -> Int -> m (Stream Int)
30+sourceIntFromToFromStream value n = S.fold A.write $ S.enumerateFromTo n (n + value)
31+
32+-------------------------------------------------------------------------------
33+-- Bench groups
34+-------------------------------------------------------------------------------
35+
36+o_1_space_generation :: Int -> [Benchmark]
37+o_1_space_generation value =
38+ [ bgroup
39+ "generation"
40+ [ benchIOSrc "write . intFromTo" (sourceIntFromToFromStream value)
41+ ]
42+ ]
43+
44+moduleName :: String
45+moduleName = "Data.Array.Prim.Pinned"
46+
47+defStreamSize :: Int
48+defStreamSize = defaultStreamSize
49+
50+main :: IO ()
51+main = runWithCLIOpts defStreamSize allBenchmarks
52+
53+ where
54+
55+ allBenchmarks size =
56+ [ bgroup (o_1_space_prefix moduleName) $
57+ o_1_space_generation size
58+ ] ++ commonBenchmarks size
benchmark/Streamly/Benchmark/Data/ArrayOps.hs+1−14
@@ -10,9 +10,7 @@
10{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE ScopedTypeVariables #-}
11
11
12-- CPP:
12-- CPP:
13−-- MEMORY_ARRAY
14-- DATA_ARRAY
13-- DATA_ARRAY
15−-- DATA_ARRAY_PRIM_PINNED
16
14
17module Streamly.Benchmark.Data.ArrayOps where
15module Streamly.Benchmark.Data.ArrayOps where
18
16
@@ -22,18 +20,13 @@ import Prelude (Bool, Int, Maybe(..), ($), (+), (.), (==), (>), undefined)
22import qualified Prelude as P
20import qualified Prelude as P
23import qualified Streamly.Prelude as S
21import qualified Streamly.Prelude as S
24
22
25−#if !defined(DATA_ARRAY_PRIM_PINNED)
26#ifdef DEVBUILD
23#ifdef DEVBUILD
27{-
24{-
28import qualified Data.Foldable as F
25import qualified Data.Foldable as F
29-}
26-}
30#endif
27#endif
31−#endif
32
28
33−#if defined(DATA_ARRAY_PRIM_PINNED)
34−import qualified Streamly.Internal.Data.Array.Prim.Pinned as A
35−type Stream = A.Array
36−#elif defined(DATA_ARRAY)
29+#if defined(DATA_ARRAY)
37import qualified Streamly.Internal.Data.Array as A
30import qualified Streamly.Internal.Data.Array as A
38type Stream = A.Array
31type Stream = A.Array
39#endif
32#endif
@@ -49,7 +42,6 @@ type Stream = A.Array
49-------------------------------------------------------------------------------
42-------------------------------------------------------------------------------
50-- CPP Common to:
43-- CPP Common to:
51-- DATA_ARRAY
44-- DATA_ARRAY
52−-- DATA_ARRAY_PRIM_PINNED
53-------------------------------------------------------------------------------
45-------------------------------------------------------------------------------
54
46
55{-# INLINE sourceUnfoldr #-}
47{-# INLINE sourceUnfoldr #-}
@@ -77,7 +69,6 @@ sourceIntFromToFromList value n = P.return $ A.fromList $ [n..n + value]
77-------------------------------------------------------------------------------
69-------------------------------------------------------------------------------
78-- CPP Common to:
70-- CPP Common to:
79-- DATA_ARRAY
71-- DATA_ARRAY
80−-- DATA_ARRAY_PRIM_PINNED
81-------------------------------------------------------------------------------
72-------------------------------------------------------------------------------
82
73
83-- CPP:
74-- CPP:
@@ -92,7 +83,6 @@ sourceIntFromToFromStream value n = S.fold A.write $ S.enumerateFromTo n (n + va
92-------------------------------------------------------------------------------
83-------------------------------------------------------------------------------
93-- CPP Common to:
84-- CPP Common to:
94-- DATA_ARRAY
85-- DATA_ARRAY
95−-- DATA_ARRAY_PRIM_PINNED
96-------------------------------------------------------------------------------
86-------------------------------------------------------------------------------
97
87
98{-# INLINE composeN #-}
88{-# INLINE composeN #-}
@@ -156,7 +146,6 @@ pureFoldl' = S.foldl' (+) 0 . S.unfold A.read
156-------------------------------------------------------------------------------
146-------------------------------------------------------------------------------
157
147
158-- CPP:
148-- CPP:
159−#if !defined(DATA_ARRAY_PRIM_PINNED)
160{-# INLINE readInstance #-}
149{-# INLINE readInstance #-}
161readInstance :: P.String -> Stream Int
150readInstance :: P.String -> Stream Int
162readInstance str =
151readInstance str =
@@ -176,7 +165,6 @@ foldableSum :: Stream Int -> Int
176foldableSum = P.sum
165foldableSum = P.sum
177-}
166-}
178#endif
167#endif
179−#endif
180
168
181-------------------------------------------------------------------------------
169-------------------------------------------------------------------------------
182-- Elimination
170-- Elimination
@@ -185,7 +173,6 @@ foldableSum = P.sum
185-------------------------------------------------------------------------------
173-------------------------------------------------------------------------------
186-- CPP Common to:
174-- CPP Common to:
187-- DATA_ARRAY
175-- DATA_ARRAY
188−-- DATA_ARRAY_PRIM_PINNED
189-------------------------------------------------------------------------------
176-------------------------------------------------------------------------------
190
177
191{-# INLINE unfoldReadDrain #-}
178{-# INLINE unfoldReadDrain #-}
benchmark/streamly-benchmarks.cabal+1−4
@@ -476,10 +476,7 @@ benchmark Data.SmallArray
476benchmark Data.Array.Prim.Pinned
476benchmark Data.Array.Prim.Pinned
477 import: bench-options
477 import: bench-options
478 type: exitcode-stdio-1.0
478 type: exitcode-stdio-1.0
479− hs-source-dirs: .
480− main-is: Streamly/Benchmark/Data/Array.hs
479+ main-is: Streamly/Benchmark/Data/Array/Prim/Pinned.hs
481− other-modules: Streamly.Benchmark.Data.ArrayOps
482− cpp-options: -DDATA_ARRAY_PRIM_PINNED
483
480
484benchmark Data.Array.Foreign
481benchmark Data.Array.Foreign
485 import: bench-options
482 import: bench-options
streamly.cabal+1
@@ -61,6 +61,7 @@ extra-source-files:
61 benchmark/Streamly/Benchmark/Data/Array/SmallArray.hs
61 benchmark/Streamly/Benchmark/Data/Array/SmallArray.hs
62 benchmark/Streamly/Benchmark/Data/Array/Foreign.hs
62 benchmark/Streamly/Benchmark/Data/Array/Foreign.hs
63 benchmark/Streamly/Benchmark/Data/Array/Prim.hs
63 benchmark/Streamly/Benchmark/Data/Array/Prim.hs
64+ benchmark/Streamly/Benchmark/Data/Array/Prim/Pinned.hs
64 benchmark/Streamly/Benchmark/Data/Array/Stream/Foreign.hs
65 benchmark/Streamly/Benchmark/Data/Array/Stream/Foreign.hs
65 benchmark/Streamly/Benchmark/Data/Parser/*.hs
66 benchmark/Streamly/Benchmark/Data/Parser/*.hs
66 benchmark/Streamly/Benchmark/Data/Stream/*.hs
67 benchmark/Streamly/Benchmark/Data/Stream/*.hs