@@ -5,6 +5,7 @@
5-- License : BSD-3-Clause
5-- License : BSD-3-Clause
6-- Maintainer : streamly@composewell.com
6-- Maintainer : streamly@composewell.com
8{-# LANGUAGE FlexibleContexts #-}
9{-# LANGUAGE FlexibleContexts #-}
10module Main
11module Main
@@ -18,6 +19,13 @@ import Data.Foldable (asum)
18import Data.Functor (($>))
19import Data.Functor (($>))
19import Data.Maybe (fromMaybe)
20import Data.Maybe (fromMaybe)
20import Data.Monoid (Sum(..))
21import Data.Monoid (Sum(..))
22+import GHC.Magic (inline)
23+#if __GLASGOW_HASKELL__ >= 802
24+import GHC.Magic (noinline)
28+import System.IO (Handle)
21import System.Random (randomRIO)
29import System.Random (randomRIO)
22import Prelude
30import Prelude
23 hiding (any, all, take, sequence, sequence_, sequenceA, takeWhile)
31 hiding (any, all, take, sequence, sequence_, sequenceA, takeWhile)
@@ -25,14 +33,16 @@ import Prelude
25import qualified Data.Traversable as TR
33import qualified Data.Traversable as TR
26import qualified Data.Foldable as F
34import qualified Data.Foldable as F
27import qualified Control.Applicative as AP
35import qualified Control.Applicative as AP
36+import qualified Streamly.FileSystem.Handle as Handle
28import qualified Streamly.Prelude as S
37import qualified Streamly.Prelude as S
29import qualified Streamly.Internal.Data.Fold as FL
38import qualified Streamly.Internal.Data.Fold as FL
30import qualified Streamly.Internal.Data.Parser as PR
39import qualified Streamly.Internal.Data.Parser as PR
31import qualified Streamly.Internal.Data.Stream.IsStream as IP
40import qualified Streamly.Internal.Data.Stream.IsStream as IP
33−import Gauge
42+import Gauge hiding (env)
34import Streamly.Prelude (SerialT)
43import Streamly.Prelude (SerialT)
35import Streamly.Benchmark.Common
44import Streamly.Benchmark.Common
45+import Streamly.Benchmark.Common.Handle
37-------------------------------------------------------------------------------
47-------------------------------------------------------------------------------
38-- Utilities
48-- Utilities
@@ -218,6 +228,13 @@ longestAllAny value =
218 (PR.drainWhile (<= value))
228 (PR.drainWhile (<= value))
231+parseManyChunksOfSum :: Int -> Handle -> IO Int
232+parseManyChunksOfSum n inh =
235+ (PR.fromFold $ FL.takeLE n FL.sum)
236+ (S.unfold Handle.read inh)
221-------------------------------------------------------------------------------
238-------------------------------------------------------------------------------
222-- Parsers in which -fspec-constr-recursive=16 is problematic
239-- Parsers in which -fspec-constr-recursive=16 is problematic
223-------------------------------------------------------------------------------
240-------------------------------------------------------------------------------
@@ -313,6 +330,14 @@ o_1_space_serial value =
313 , benchIOSink value "parseIterate" parseIterate
330 , benchIOSink value "parseIterate" parseIterate
333+o_1_space_filesystem :: BenchEnv -> [Benchmark]
334+o_1_space_filesystem env =
335+ [ mkBench ("S.parseMany (FL.take " ++ show (bigSize env) ++ " FL.sum)") env
336+ $ \inh _ -> noinline parseManyChunksOfSum (bigSize env) inh
337+ , mkBench "S.parseMany (FL.take 1 FL.sum)" env
338+ $ \inh _ -> inline parseManyChunksOfSum 1 inh
316o_n_heap_serial :: Int -> [Benchmark]
341o_n_heap_serial :: Int -> [Benchmark]
317o_n_heap_serial value =
342o_n_heap_serial value =
@@ -344,11 +369,15 @@ o_n_heap_serial value =
344main :: IO ()
369main :: IO ()
346 (value, cfg, benches) <- parseCLIOpts defaultStreamSize
371 (value, cfg, benches) <- parseCLIOpts defaultStreamSize
372+ env <- mkHandleBenchEnv
347− value `seq` runMode (mode cfg) cfg benches (allBenchmarks value)
373+ value `seq` runMode (mode cfg) cfg benches (allBenchmarks env value)
351− allBenchmarks value =
377+ allBenchmarks env value =
352 [ bgroup (o_1_space_prefix moduleName) (o_1_space_serial value)
378 [ bgroup (o_1_space_prefix moduleName) (o_1_space_serial value)
380+ (o_1_space_prefix moduleName ++ "/filesystem")
381+ (o_1_space_filesystem env)
353 , bgroup (o_n_heap_prefix moduleName) (o_n_heap_serial value)
382 , bgroup (o_n_heap_prefix moduleName) (o_n_heap_serial value)