@@ -5,6 +5,7 @@
55-- License : BSD-3-Clause
66-- Maintainer : streamly@composewell.com
77
8+{-# LANGUAGE CPP #-}
89{-# LANGUAGE FlexibleContexts #-}
910
1011module Main
@@ -18,6 +19,13 @@ import Data.Foldable (asum)
1819import Data.Functor (($>))
1920import Data.Maybe (fromMaybe)
2021import Data.Monoid (Sum(..))
22+import GHC.Magic (inline)
23+#if __GLASGOW_HASKELL__ >= 802
24+import GHC.Magic (noinline)
25+#else
26+#define noinline
27+#endif
28+import System.IO (Handle)
2129import System.Random (randomRIO)
2230import Prelude
2331 hiding (any, all, take, sequence, sequence_, sequenceA, takeWhile)
@@ -25,14 +33,16 @@ import Prelude
2533import qualified Data.Traversable as TR
2634import qualified Data.Foldable as F
2735import qualified Control.Applicative as AP
36+import qualified Streamly.FileSystem.Handle as Handle
2837import qualified Streamly.Prelude as S
2938import qualified Streamly.Internal.Data.Fold as FL
3039import qualified Streamly.Internal.Data.Parser as PR
3140import qualified Streamly.Internal.Data.Stream.IsStream as IP
3241
33−import Gauge
42+import Gauge hiding (env)
3443import Streamly.Prelude (SerialT)
3544import Streamly.Benchmark.Common
45+import Streamly.Benchmark.Common.Handle
3646
3747-------------------------------------------------------------------------------
3848-- Utilities
@@ -218,6 +228,13 @@ longestAllAny value =
218228 (PR.drainWhile (<= value))
219229 )
220230
231+parseManyChunksOfSum :: Int -> Handle -> IO Int
232+parseManyChunksOfSum n inh =
233+ S.length
234+ $ IP.parseMany
235+ (PR.fromFold $ FL.takeLE n FL.sum)
236+ (S.unfold Handle.read inh)
237+
221238-------------------------------------------------------------------------------
222239-- Parsers in which -fspec-constr-recursive=16 is problematic
223240-------------------------------------------------------------------------------
@@ -313,6 +330,14 @@ o_1_space_serial value =
313330 , benchIOSink value "parseIterate" parseIterate
314331 ]
315332
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
339+ ]
340+
316341o_n_heap_serial :: Int -> [Benchmark]
317342o_n_heap_serial value =
318343 [
@@ -344,11 +369,15 @@ o_n_heap_serial value =
344369main :: IO ()
345370main = do
346371 (value, cfg, benches) <- parseCLIOpts defaultStreamSize
347− value `seq` runMode (mode cfg) cfg benches (allBenchmarks value)
372+ env <- mkHandleBenchEnv
373+ value `seq` runMode (mode cfg) cfg benches (allBenchmarks env value)
348374
349375 where
350376
351− allBenchmarks value =
377+ allBenchmarks env value =
352378 [ bgroup (o_1_space_prefix moduleName) (o_1_space_serial value)
379+ , bgroup
380+ (o_1_space_prefix moduleName ++ "/filesystem")
381+ (o_1_space_filesystem env)
353382 , bgroup (o_n_heap_prefix moduleName) (o_n_heap_serial value)
354383 ]