on master help sign in
Move parseMany benchamrks from FileSystem.Handle to Data.Parser
commitb04187b60261def09b015f5efe18362655696555 authorAdithya Kumar <adithya@composewell.com> dateSun 14 Feb 2021, 04:26 (6 years ago) parent9ebca6e
2 files changed+32−17
benchmark/Streamly/Benchmark/Data/Parser.hs+32−3 benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs−14
benchmark/Streamly/Benchmark/Data/Parser.hs+32−3
@@ -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 ]
benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs−14
@@ -36,7 +36,6 @@ import qualified Streamly.FileSystem.Handle as FH
3636import qualified Streamly.Internal.Data.Array.Foreign as A
3737import qualified Streamly.Internal.Data.Array.Foreign.Types as AT
3838import qualified Streamly.Internal.Data.Fold as FL
39−import qualified Streamly.Internal.Data.Parser as PR
4039import qualified Streamly.Internal.Data.Stream.IsStream as IP
4140import qualified Streamly.Internal.FileSystem.Handle as IFH
4241import qualified Streamly.Internal.Data.Array.Stream.Foreign as AS
@@ -318,11 +317,6 @@ foldManyChunksOfSum :: Int -> Handle -> IO Int
318317foldManyChunksOfSum n inh =
319318 S.length $ IP.foldMany (FL.takeLE n FL.sum) (S.unfold FH.read inh)
320319
321−parseManyChunksOfSum :: Int -> Handle -> IO Int
322−parseManyChunksOfSum n inh =
323− S.length
324− $ IP.parseMany (PR.fromFold $ FL.takeLE n FL.sum) (S.unfold FH.read inh)
325−
326320-- XXX investigate why we need an INLINE in this case (GHC)
327321-- Even though allocations remain the same in both cases inlining improves time
328322-- by 4x.
@@ -373,14 +367,6 @@ o_1_space_reduce_read_grouped env =
373367 "S.foldMany (FL.take 1 FL.sum)"
374368 env
375369 $ \inh _ -> inline foldManyChunksOfSum 1 inh
376− , mkBench
377− ("S.parseMany (FL.take " ++ show (bigSize env) ++ " FL.sum)")
378− env
379− $ \inh _ -> noinline parseManyChunksOfSum (bigSize env) inh
380− , mkBench
381− "S.parseMany (FL.take 1 FL.sum)"
382− env
383− $ \inh _ -> inline parseManyChunksOfSum 1 inh
384370
385371 -- folding chunks to arrays
386372 , mkBenchSmall "S.chunksOf 1" env $ \inh _ ->