@@ -1,7 +1,6 @@
11-- |
2−-- Module : Streamly.Benchmark.Data.Mut.Array
3−-- Copyright : (c) 2020 Composewell Technologies
4−--
2+-- Module : Streamly.Benchmark.Data.Array.Foreign.Mut
3+-- Copyright : (c) 2021 Composewell Technologies
54-- License : BSD-3-Clause
65-- Maintainer : streamly@composewell.com
76
@@ -18,29 +17,18 @@
1817{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
1918#endif
2019
21−module Main
22− (
23− main
24− ) where
20+module Main (main) where
2521
2622import Control.DeepSeq (NFData(..))
23+import Streamly.Prelude (MonadAsync, SerialT, IsStream)
2724import System.Random (randomRIO)
28−import Prelude hiding ()
2925
30−import qualified Streamly.Prelude as Stream
31−import qualified Streamly.Internal.Data.Fold as Fold
32−import qualified Streamly.Internal.Data.Array.Stream.Mut.Foreign as MArray
26+import qualified Streamly.Prelude as Stream
27+import qualified Streamly.Internal.Data.Array.Foreign.Mut as MArray
3328
3429import Gauge hiding (env)
35−import Streamly.Prelude (SerialT, MonadAsync, IsStream)
3630import Streamly.Benchmark.Common
3731
38−#ifdef INSPECTION
39−import Foreign.Storable (Storable)
40−import Streamly.Internal.Data.Stream.StreamD.Type (Step(..))
41−import Test.Inspection
42−#endif
43−
4432-------------------------------------------------------------------------------
4533-- Utilities
4634-------------------------------------------------------------------------------
@@ -57,21 +45,20 @@ sourceUnfoldrM value n = Stream.unfoldrM step n
5745{-# INLINE benchIO #-}
5846benchIO
5947 :: NFData b
60− => String -> (Int -> t IO a) -> (t IO a -> IO b) -> Benchmark
48+ => String -> (Int -> a) -> (a -> IO b) -> Benchmark
6149benchIO name src sink =
6250 bench name $ nfIO $ randomRIO (1,1) >>= sink . src
6351
64−{-# INLINE partitionBy #-}
65−partitionBy :: Int -> SerialT IO (MArray.Array Int) -> IO ()
66−partitionBy value s = Stream.fold Fold.drain $ do
67− a <- s
68− MArray.partitionBy ( < value) a
69−
70−o_n_space_serial_marray ::
71− Int -> [MArray.Array Int] -> [Benchmark]
72−o_n_space_serial_marray bound arrays =
73− [ benchIO "partitionBy" (\_ -> Stream.fromList arrays)
74− $ partitionBy bound
52+o_n_space_serial_marray :: Int -> MArray.Array Int -> [Benchmark]
53+o_n_space_serial_marray value array =
54+ [ benchIO "partitionBy (< 0)" (const array)
55+ $ MArray.partitionBy (< 0)
56+ , benchIO "partitionBy (> 0)" (const array)
57+ $ MArray.partitionBy (> 0)
58+ , benchIO "partitionBy (< value/2)" (const array)
59+ $ MArray.partitionBy (< (value `div` 2))
60+ , benchIO "partitionBy (> value/2)" (const array)
61+ $ MArray.partitionBy (> (value `div` 2))
7562 ]
7663
7764-------------------------------------------------------------------------------
@@ -79,7 +66,7 @@ o_n_space_serial_marray bound arrays =
7966-------------------------------------------------------------------------------
8067
8168moduleName :: String
82−moduleName = "Data.Mut.Array"
69+moduleName = "Data.Array.Foreign.Mut"
8370
8471main :: IO ()
8572main = do
@@ -87,10 +74,9 @@ main = do
8774
8875 where
8976
90− alloc value =
91− Stream.toList $ MArray.arraysOf value $ sourceUnfoldrM value 0
77+ alloc value = MArray.fromStream (sourceUnfoldrM value 0 :: SerialT IO Int)
9278
93− allBenchmarks arrays value =
79+ allBenchmarks array value =
9480 [ bgroup (o_1_space_prefix moduleName) $
95− o_n_space_serial_marray value arrays
81+ o_n_space_serial_marray value array
9682 ]