@@ -1,7 +1,6 @@
2−-- Module : Streamly.Benchmark.Data.Mut.Array
2+-- Module : Streamly.Benchmark.Data.Array.Foreign.Mut
3−-- Copyright : (c) 2020 Composewell Technologies
3+-- Copyright : (c) 2021 Composewell Technologies
5-- License : BSD-3-Clause
4-- License : BSD-3-Clause
6-- Maintainer : streamly@composewell.com
5-- Maintainer : streamly@composewell.com
@@ -18,29 +17,18 @@
18{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
17{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
21−module Main
20+module Main (main) where
26import Control.DeepSeq (NFData(..))
22import Control.DeepSeq (NFData(..))
23+import Streamly.Prelude (MonadAsync, SerialT, IsStream)
27import System.Random (randomRIO)
24import System.Random (randomRIO)
28−import Prelude hiding ()
30−import qualified Streamly.Prelude as Stream
26+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
27+import qualified Streamly.Internal.Data.Array.Foreign.Mut as MArray
34import Gauge hiding (env)
29import Gauge hiding (env)
35−import Streamly.Prelude (SerialT, MonadAsync, IsStream)
36import Streamly.Benchmark.Common
30import Streamly.Benchmark.Common
39−import Foreign.Storable (Storable)
40−import Streamly.Internal.Data.Stream.StreamD.Type (Step(..))
41−import Test.Inspection
44-------------------------------------------------------------------------------
32-------------------------------------------------------------------------------
45-- Utilities
33-- Utilities
46-------------------------------------------------------------------------------
34-------------------------------------------------------------------------------
@@ -57,21 +45,20 @@ sourceUnfoldrM value n = Stream.unfoldrM step n
57{-# INLINE benchIO #-}
45{-# INLINE benchIO #-}
59 :: NFData b
47 :: NFData b
60− => String -> (Int -> t IO a) -> (t IO a -> IO b) -> Benchmark
48+ => String -> (Int -> a) -> (a -> IO b) -> Benchmark
61benchIO name src sink =
49benchIO name src sink =
62 bench name $ nfIO $ randomRIO (1,1) >>= sink . src
50 bench name $ nfIO $ randomRIO (1,1) >>= sink . src
64−{-# INLINE partitionBy #-}
65−partitionBy :: Int -> SerialT IO (MArray.Array Int) -> IO ()
66−partitionBy value s = Stream.fold Fold.drain $ do
68− MArray.partitionBy ( < value) a
70−o_n_space_serial_marray ::
71− Int -> [MArray.Array Int] -> [Benchmark]
52+o_n_space_serial_marray :: Int -> MArray.Array Int -> [Benchmark]
72−o_n_space_serial_marray bound arrays =
53+o_n_space_serial_marray value array =
73− [ benchIO "partitionBy" (\_ -> Stream.fromList arrays)
54+ [ benchIO "partitionBy (< 0)" (const array)
55+ $ MArray.partitionBy (< 0)
56+ , benchIO "partitionBy (> 0)" (const array)
57+ $ MArray.partitionBy (> 0)
74− $ partitionBy bound
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))
77-------------------------------------------------------------------------------
64-------------------------------------------------------------------------------
@@ -79,7 +66,7 @@ o_n_space_serial_marray bound arrays =
79-------------------------------------------------------------------------------
66-------------------------------------------------------------------------------
81moduleName :: String
68moduleName :: String
82−moduleName = "Data.Mut.Array"
69+moduleName = "Data.Array.Foreign.Mut"
84main :: IO ()
71main :: IO ()
@@ -87,10 +74,9 @@ main = do
91− Stream.toList $ MArray.arraysOf value $ sourceUnfoldrM value 0
77+ alloc value = MArray.fromStream (sourceUnfoldrM value 0 :: SerialT IO Int)
93− allBenchmarks arrays value =
79+ allBenchmarks array value =
94 [ bgroup (o_1_space_prefix moduleName) $
80 [ bgroup (o_1_space_prefix moduleName) $
95− o_n_space_serial_marray value arrays
81+ o_n_space_serial_marray value array