on master help sign in
Move benchmarks of Array.Prim.Pinned out of common benchmark mess
commitf8d80ccc0ddb67a02ce625e5448507f49e7d908d authoradithyaov <adithya@composewell.com> dateSun 28 Nov 2021, 20:12 (5 years ago) parentad1bb0d
5 files changed+62−40
benchmark/Streamly/Benchmark/Data/Array.hs+1−22 benchmark/Streamly/Benchmark/Data/Array/Prim/Pinned.hs+58 benchmark/Streamly/Benchmark/Data/ArrayOps.hs+1−14 benchmark/streamly-benchmarks.cabal+1−4 streamly.cabal+1
benchmark/Streamly/Benchmark/Data/Array.hs+1−22
@@ -28,9 +28,7 @@ import Gauge
2828import Streamly.Benchmark.Common hiding (benchPureSrc)
2929import qualified Streamly.Benchmark.Prelude as P
3030
31−#if !defined(DATA_ARRAY_PRIM) && !defined(DATA_ARRAY_PRIM_PINNED)
3231import Control.DeepSeq (deepseq)
33−#endif
3432
3533-------------------------------------------------------------------------------
3634--
@@ -43,11 +41,7 @@ benchIO name src f = bench name $ nfIO $
4341
4442-- Drain a source that generates an array in the IO monad
4543{-# 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
5145benchIOSrc name src = benchIO name src id
5246
5347{-# INLINE benchPureSink #-}
@@ -76,17 +70,8 @@ o_1_space_generation value =
7670 (Ops.sourceIntFromToFromList value)
7771 , benchIOSrc "writeN . unfoldr" (Ops.sourceUnfoldr value)
7872 , 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
8673 , let testStr = mkListString value
87−#endif
8874 in testStr `deepseq` (bench "read" $ nf Ops.readInstance testStr)
89−#endif
9075 , benchPureSink value "show" Ops.showInstance
9176 ]
9277 ]
@@ -106,13 +91,11 @@ o_1_space_elimination value =
10691 (S.fold (IA.writeLastN 1)) (P.sourceUnfoldrM value)
10792 , benchFold "writeLastN.10"
10893 (S.fold (IA.writeLastN 10)) (P.sourceUnfoldrM value)
109−#if !defined(DATA_ARRAY_PRIM) && !defined(DATA_ARRAY_PRIM_PINNED)
11094#ifdef DEVBUILD
11195{-
11296 , benchPureSink value "foldable/foldl'" Ops.foldableFoldl'
11397 , benchPureSink value "foldable/sum" Ops.foldableSum
11498-}
115−#endif
11699#endif
117100 ]
118101 ]
@@ -148,11 +131,7 @@ o_1_space_transformationX4 value =
148131 ]
149132
150133moduleName :: String
151−#if defined(DATA_ARRAY_PRIM_PINNED)
152−moduleName = "Data.Array.Prim.Pinned"
153−#else
154134moduleName = "Data.Array"
155−#endif
156135
157136defStreamSize :: Int
158137defStreamSize = 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 @@
1010{-# LANGUAGE ScopedTypeVariables #-}
1111
1212-- CPP:
13−-- MEMORY_ARRAY
1413-- DATA_ARRAY
15−-- DATA_ARRAY_PRIM_PINNED
1614
1715module Streamly.Benchmark.Data.ArrayOps where
1816
@@ -22,18 +20,13 @@ import Prelude (Bool, Int, Maybe(..), ($), (+), (.), (==), (>), undefined)
2220import qualified Prelude as P
2321import qualified Streamly.Prelude as S
2422
25−#if !defined(DATA_ARRAY_PRIM_PINNED)
2623#ifdef DEVBUILD
2724{-
2825import qualified Data.Foldable as F
2926-}
3027#endif
31−#endif
3228
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)
3730import qualified Streamly.Internal.Data.Array as A
3831type Stream = A.Array
3932#endif
@@ -49,7 +42,6 @@ type Stream = A.Array
4942-------------------------------------------------------------------------------
5043-- CPP Common to:
5144-- DATA_ARRAY
52−-- DATA_ARRAY_PRIM_PINNED
5345-------------------------------------------------------------------------------
5446
5547{-# INLINE sourceUnfoldr #-}
@@ -77,7 +69,6 @@ sourceIntFromToFromList value n = P.return $ A.fromList $ [n..n + value]
7769-------------------------------------------------------------------------------
7870-- CPP Common to:
7971-- DATA_ARRAY
80−-- DATA_ARRAY_PRIM_PINNED
8172-------------------------------------------------------------------------------
8273
8374-- CPP:
@@ -92,7 +83,6 @@ sourceIntFromToFromStream value n = S.fold A.write $ S.enumerateFromTo n (n + va
9283-------------------------------------------------------------------------------
9384-- CPP Common to:
9485-- DATA_ARRAY
95−-- DATA_ARRAY_PRIM_PINNED
9686-------------------------------------------------------------------------------
9787
9888{-# INLINE composeN #-}
@@ -156,7 +146,6 @@ pureFoldl' = S.foldl' (+) 0 . S.unfold A.read
156146-------------------------------------------------------------------------------
157147
158148-- CPP:
159−#if !defined(DATA_ARRAY_PRIM_PINNED)
160149{-# INLINE readInstance #-}
161150readInstance :: P.String -> Stream Int
162151readInstance str =
@@ -176,7 +165,6 @@ foldableSum :: Stream Int -> Int
176165foldableSum = P.sum
177166-}
178167#endif
179−#endif
180168
181169-------------------------------------------------------------------------------
182170-- Elimination
@@ -185,7 +173,6 @@ foldableSum = P.sum
185173-------------------------------------------------------------------------------
186174-- CPP Common to:
187175-- DATA_ARRAY
188−-- DATA_ARRAY_PRIM_PINNED
189176-------------------------------------------------------------------------------
190177
191178{-# INLINE unfoldReadDrain #-}
benchmark/streamly-benchmarks.cabal+1−4
@@ -476,10 +476,7 @@ benchmark Data.SmallArray
476476benchmark Data.Array.Prim.Pinned
477477 import: bench-options
478478 type: exitcode-stdio-1.0
479− hs-source-dirs: .
480− main-is: Streamly/Benchmark/Data/Array.hs
481− other-modules: Streamly.Benchmark.Data.ArrayOps
482− cpp-options: -DDATA_ARRAY_PRIM_PINNED
479+ main-is: Streamly/Benchmark/Data/Array/Prim/Pinned.hs
483480
484481benchmark Data.Array.Foreign
485482 import: bench-options
streamly.cabal+1
@@ -61,6 +61,7 @@ extra-source-files:
6161 benchmark/Streamly/Benchmark/Data/Array/SmallArray.hs
6262 benchmark/Streamly/Benchmark/Data/Array/Foreign.hs
6363 benchmark/Streamly/Benchmark/Data/Array/Prim.hs
64+ benchmark/Streamly/Benchmark/Data/Array/Prim/Pinned.hs
6465 benchmark/Streamly/Benchmark/Data/Array/Stream/Foreign.hs
6566 benchmark/Streamly/Benchmark/Data/Parser/*.hs
6667 benchmark/Streamly/Benchmark/Data/Stream/*.hs