on master help sign in
Make Data.Stream benchmark build with streamly-core
commita14c05807b019b094d1d9570ec42a98bede1e245 authorHarendra Kumar <harendra@composewell.com> dateSat 27 Aug 2022, 13:59 (4 years ago) parent9e380ee
7 files changed+33−23
benchmark/Streamly/Benchmark/Data/Stream/Common.hs+6−1 benchmark/Streamly/Benchmark/Data/Stream/Exceptions.hs+20−8 benchmark/Streamly/Benchmark/Data/Stream/Expand.hs−1 benchmark/Streamly/Benchmark/Data/Stream/Lift.hs+2−4 benchmark/Streamly/Benchmark/Data/Stream/Reduce.hs+2−3 benchmark/Streamly/Benchmark/Data/Stream/Transform.hs−2 benchmark/streamly-benchmarks.cabal+3−4
benchmark/Streamly/Benchmark/Data/Stream/Common.hs+6−1
@@ -34,6 +34,7 @@ module Stream.Common
3434 -- Benchmark stream elimination
3535 , benchIOSink
3636 , benchIOSrc
37+ , benchIO
3738
3839 -- Benchmarking functions
3940 , concatStreamsWith
@@ -62,6 +63,7 @@ module Stream.Common
6263where
6364
6465import Control.Applicative (liftA2)
66+import Control.DeepSeq (NFData)
6567import Control.Exception (try)
6668import GHC.Exception (ErrorCall)
6769import Streamly.Internal.Data.Stream (Stream)
@@ -79,7 +81,6 @@ import Streamly.Benchmark.Prelude
7981 , concatStreamsWith, concatPairsWith
8082 )
8183#else
82−import Control.DeepSeq (NFData)
8384import qualified Streamly.Internal.Data.Stream as Stream
8485#endif
8586
@@ -183,6 +184,10 @@ benchIOSrc
183184benchIOSrc name f =
184185 bench name $ nfIO $ randomRIO (1,1) >>= drain . f
185186
187+{-# NOINLINE benchIO #-}
188+benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
189+benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
190+
186191#ifndef USE_PRELUDE
187192{-# INLINE concatStreamsWith #-}
188193concatStreamsWith
benchmark/Streamly/Benchmark/Data/Stream/Exceptions.hs+20−8
@@ -21,17 +21,22 @@
2121
2222module Stream.Exceptions (benchmarks) where
2323
24−import Control.Exception (SomeException, Exception, throwIO)
24+import Control.Exception (Exception, throwIO)
2525import Stream.Common (drain)
2626import Streamly.Internal.Data.Stream (Stream)
27−import System.IO (Handle, hClose, hPutChar)
2827
2928import qualified Data.IORef as Ref
3029import qualified Data.Map.Strict as Map
3130import qualified Stream.Common as Common
31+
32+#ifndef USE_STREAMLY_CORE
33+import Control.Exception (SomeException)
34+import System.IO (Handle, hClose, hPutChar)
3235import qualified Streamly.FileSystem.Handle as FH
33−import qualified Streamly.Internal.Data.Unfold as IUF
3436import qualified Streamly.Internal.FileSystem.Handle as IFH
37+import qualified Streamly.Internal.Data.Unfold as IUF
38+#endif
39+
3540#ifdef USE_PRELUDE
3641import qualified Streamly.Internal.Data.Stream.IsStream as Stream
3742#else
@@ -134,6 +139,9 @@ o_1_space_serial_exceptions length =
134139 ]
135140 ]
136141
142+-- XXX Move these to FileSystem.Handle benchmarks
143+#ifndef USE_STREAMLY_CORE
144+
137145-------------------------------------------------------------------------------
138146-- copy stream exceptions
139147-------------------------------------------------------------------------------
@@ -323,12 +331,16 @@ o_1_space_copy_exceptions_toChunks env =
323331 ]
324332 ]
325333
334+#endif
335+
326336benchmarks :: String -> BenchEnv -> Int -> [Benchmark]
327−benchmarks moduleName env size =
337+benchmarks moduleName _env size =
328338 [ bgroup (o_1_space_prefix moduleName) $ concat
329− [ o_1_space_copy_exceptions_readChunks env
330− , o_1_space_copy_exceptions_toChunks env
331− , o_1_space_copy_stream_exceptions env
332− , o_1_space_serial_exceptions size
339+ [ o_1_space_serial_exceptions size
340+#ifndef USE_STREAMLY_CORE
341+ , o_1_space_copy_exceptions_readChunks _env
342+ , o_1_space_copy_exceptions_toChunks _env
343+ , o_1_space_copy_stream_exceptions _env
344+#endif
333345 ]
334346 ]
benchmark/Streamly/Benchmark/Data/Stream/Expand.hs−1
@@ -32,7 +32,6 @@ import Test.Inspection
3232import qualified Streamly.Internal.Data.Stream.StreamD as D
3333#endif
3434
35−import Streamly.Benchmark.Prelude (benchIO)
3635import qualified Stream.Common as Common
3736#ifdef USE_PRELUDE
3837import qualified Streamly.Internal.Data.Stream.IsStream as S
benchmark/Streamly/Benchmark/Data/Stream/Lift.hs+2−4
@@ -15,14 +15,12 @@ import Control.DeepSeq (NFData(..))
1515import Control.Monad.Trans.Class (lift)
1616import Control.Monad.State.Strict (StateT, get, put, MonadState)
1717import Data.Functor.Identity (Identity)
18−import Stream.Common (sourceUnfoldr, sourceUnfoldrM, benchIOSrc, drain)
18+import Stream.Common
19+ (benchIO, sourceUnfoldr, sourceUnfoldrM, benchIOSrc, drain)
1920import System.Random (randomRIO)
2021#ifdef USE_PRELUDE
21−import Streamly.Benchmark.Prelude hiding
22− (sourceUnfoldr, sourceUnfoldrM, benchIOSrc)
2322import qualified Streamly.Internal.Data.Stream.IsStream as Stream
2423#else
25−import Streamly.Benchmark.Prelude (benchIO)
2624import qualified Streamly.Internal.Data.Stream as Stream
2725#endif
2826import qualified Streamly.Internal.Data.Fold as Fold
benchmark/Streamly/Benchmark/Data/Stream/Reduce.hs+2−3
@@ -17,7 +17,6 @@ import Control.DeepSeq (NFData(..))
1717import Control.Monad.IO.Class (MonadIO(..))
1818import Data.Monoid (Sum(..))
1919import GHC.Generics (Generic)
20−import Streamly.Internal.Data.IsMap.HashMap ()
2120import Streamly.Internal.Data.Stream (Stream)
2221
2322import qualified Streamly.Internal.Data.Refold.Type as Refold
@@ -27,15 +26,15 @@ import qualified Stream.Common as Common
2726import Control.Monad (when)
2827import Data.Proxy (Proxy(..))
2928import Data.HashMap.Strict (HashMap)
29+import Streamly.Internal.Data.IsMap.HashMap ()
3030import qualified Streamly.Internal.Data.Stream.IsStream as S
3131import Streamly.Prelude (fromSerial)
3232import Streamly.Benchmark.Prelude hiding
33− ( benchIOSrc, sourceUnfoldrM, apDiscardFst, apDiscardSnd, apLiftA2
33+ ( benchIO, benchIOSrc, sourceUnfoldrM, apDiscardFst, apDiscardSnd, apLiftA2
3434 , toNullAp, monadThen, toNullM, toNullM3, filterAllInM, filterAllOutM
3535 , filterSome, breakAfterSome, toListM, toListSome, transformMapM
3636 , transformComposeMapM, transformTeeMapM, transformZipMapM)
3737#else
38−import Streamly.Benchmark.Prelude (benchIO)
3938import qualified Streamly.Internal.Data.Stream as S
4039#endif
4140
benchmark/Streamly/Benchmark/Data/Stream/Transform.hs−2
@@ -32,11 +32,9 @@ import qualified Prelude
3232import qualified Stream.Common as Common
3333import qualified Streamly.Internal.Data.Unfold as Unfold
3434#ifdef USE_PRELUDE
35−import Streamly.Benchmark.Prelude (benchIO)
3635import qualified Streamly.Internal.Data.Stream.IsStream as Stream
3736import Streamly.Internal.Data.Time.Units
3837#else
39−import Streamly.Benchmark.Prelude (benchIO)
4038import qualified Streamly.Internal.Data.Stream as Stream
4139#endif
4240
benchmark/streamly-benchmarks.cabal+3−4
@@ -76,6 +76,9 @@ flag use-prelude
7676common compile-options
7777 default-language: Haskell2010
7878
79+ if flag(use-streamly-core)
80+ cpp-options: -DUSE_STREAMLY_CORE
81+
7982 if flag(use-prelude)
8083 cpp-options: -DUSE_PRELUDE
8184
@@ -235,10 +238,6 @@ benchmark Data.Stream
235238 if flag(use-prelude)
236239 other-modules:
237240 Stream.Split
238− if flag(use-streamly-core) || impl(ghcjs)
239− buildable: False
240− else
241− buildable: True
242241 if flag(limit-build-mem)
243242 if flag(dev)
244243 ghc-options: +RTS -M3500M -RTS