on master help sign in
Move Streamly.Benchmark.CommonH to lib and change benchmark names, refactor
commit1ff4d3c63419acec25afd480ac7ec5d399d4fda0 authorAnurag Hooda <anuraghooda@composewell.com> dateWed 9 Dec 2020, 12:17 (6 years ago) parent425df88
11 files changed+74−76
benchmark/Streamly/Benchmark/Data/Unfold.hs+7−9 benchmark/Streamly/Benchmark/FileSystem/Handle.hs+3−2 benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+1−1 benchmark/Streamly/Benchmark/FileSystem/Handle/ReadWrite.hs+1−1 benchmark/Streamly/Benchmark/Prelude/Serial.hs+7−6 benchmark/Streamly/Benchmark/Prelude/Serial/Exceptions.hs+15−14 benchmark/Streamly/Benchmark/Prelude/Serial/Split.hs+15−14 benchmark/Streamly/Benchmark/Unicode/Stream.hs+7−8 benchmark/Streamly/Benchmark/CommonH.hs → benchmark/lib/Streamly/Benchmark/Common/Handle.hs+11−14 benchmark/streamly-benchmarks.cabal+6−6 streamly.cabal+1−1
benchmark/Streamly/Benchmark/Data/Unfold.hs+7−9
@@ -1,7 +1,6 @@
11-- |
22-- Module : Streamly.Benchmark.Data.Fold
33-- Copyright : (c) 2018 Composewell
4−--
54-- License : MIT
65-- Maintainer : streamly@composewell.com
76
@@ -22,8 +21,8 @@ module Main (main) where
2221
2322import Control.DeepSeq (NFData(..))
2423import Control.Exception (SomeException)
25−import System.IO (Handle, hClose)
2624import Streamly.Internal.Data.Unfold (Unfold)
25+import System.IO (Handle, hClose)
2726import System.Random (randomRIO)
2827
2928import qualified Prelude
@@ -39,7 +38,7 @@ import qualified Streamly.Prelude as SP
3938import Gauge hiding (env)
4039import Prelude hiding (concat, take, filter, zipWith, map, mapM, takeWhile)
4140import Streamly.Benchmark.Common
42−import Streamly.Benchmark.CommonH
41+import Streamly.Benchmark.Common.Handle
4342
4443#ifdef INSPECTION
4544import Test.Inspection
@@ -612,7 +611,7 @@ readWriteBracketUnfold inh devNull =
612611
613612o_1_space_copy_read_exceptions :: BenchEnv -> [Benchmark]
614613o_1_space_copy_read_exceptions env =
615− [ bgroup "copy/read/exceptions"
614+ [ bgroup "copy/exceptions"
616615 [ mkBenchSmall "UF.onException" env $ \inh _ ->
617616 readWriteOnExceptionUnfold inh (nullH env)
618617 , mkBenchSmall "UF.handle" env $ \inh _ ->
@@ -636,13 +635,12 @@ o_1_space_copy_read_exceptions env =
636635main :: IO ()
637636main = do
638637 (size, cfg, benches) <- parseCLIOpts defaultStreamSize
639− env <- mkBenchEnv "Benchmark_FileSystem_Handle_InputFile"
640− size `seq` runMode (mode cfg) cfg benches (allBenchmarks size <>
641− allBenchmarks' env)
638+ env <- mkHandleBenchEnv
639+ size `seq` runMode (mode cfg) cfg benches (allBenchmarks size env)
642640
643641 where
644642
645− allBenchmarks size =
643+ allBenchmarks size env =
646644 [ bgroup (o_1_space_prefix moduleName)
647645 $ Prelude.concat
648646 [ o_1_space_transformation_input size
@@ -651,8 +649,8 @@ main = do
651649 , o_1_space_filtering size
652650 , o_1_space_zip size
653651 , o_1_space_nested size
652+ , o_1_space_copy_read_exceptions env
654653 ]
655654 , bgroup (o_n_space_prefix moduleName)
656655 $ Prelude.concat [o_n_space_nested size]
657656 ]
658− allBenchmarks' = o_1_space_copy_read_exceptions
benchmark/Streamly/Benchmark/FileSystem/Handle.hs+3−2
@@ -21,13 +21,14 @@
2121#if __GLASGOW_HASKELL__ >= 800
2222#endif
2323
24+import Streamly.Benchmark.Common.Handle (mkHandleBenchEnv)
25+
2426import qualified Handle.ReadWrite as RW
2527import qualified Handle.Read as RO
2628
2729import Gauge hiding (env)
2830import Prelude hiding (last, length)
2931import Streamly.Benchmark.Common
30−import Streamly.Benchmark.CommonH
3132
3233-------------------------------------------------------------------------------
3334--
@@ -43,7 +44,7 @@ moduleName = "FileSystem.Handle"
4344main :: IO ()
4445main = do
4546 (_, cfg, benches) <- parseCLIOpts defaultStreamSize
46− env <- mkBenchEnv "Benchmark_FileSystem_Handle_InputFile"
47+ env <- mkHandleBenchEnv
4748 runMode (mode cfg) cfg benches (allBenchmarks env)
4849
4950 where
benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+1−1
@@ -47,7 +47,7 @@ import qualified Streamly.Prelude as S
4747
4848import Gauge hiding (env)
4949import Prelude hiding (last, length)
50−import Streamly.Benchmark.CommonH
50+import Streamly.Benchmark.Common.Handle
5151
5252#ifdef INSPECTION
5353import Streamly.Internal.Data.Stream.StreamD.Type (Step(..), GroupState)
benchmark/Streamly/Benchmark/FileSystem/Handle/ReadWrite.hs+1−1
@@ -34,7 +34,7 @@ import qualified Streamly.Data.Array.Storable.Foreign as A
3434import qualified Streamly.Prelude as S
3535
3636import Gauge hiding (env)
37−import Streamly.Benchmark.CommonH
37+import Streamly.Benchmark.Common.Handle
3838
3939#ifdef INSPECTION
4040import Foreign.Storable (Storable)
benchmark/Streamly/Benchmark/Prelude/Serial.hs+7−6
@@ -11,6 +11,8 @@
1111
1212module Main (main) where
1313
14+import Streamly.Benchmark.Common.Handle (mkHandleBenchEnv)
15+
1416import qualified Serial.Elimination as Elimination
1517import qualified Serial.Exceptions as Exceptions
1618import qualified Serial.Generation as Generation
@@ -22,7 +24,6 @@ import qualified Serial.Transformation3 as Transformation3
2224
2325import Gauge hiding (env)
2426import Streamly.Benchmark.Common
25−import Streamly.Benchmark.CommonH
2627
2728moduleName :: String
2829moduleName = "Prelude.Serial"
@@ -37,15 +38,15 @@ moduleName = "Prelude.Serial"
3738main :: IO ()
3839main = do
3940 (value, cfg, benches) <- parseCLIOpts defaultStreamSize
40− env <- mkBenchEnv "Benchmark_FileSystem_Handle_InputFile"
41− value `seq` runMode (mode cfg) cfg benches (allBenchmarks value <>
42− Exceptions.allBenchmarks env <>
43− Split.allBenchmarks env)
41+ env <- mkHandleBenchEnv
42+ value `seq` runMode (mode cfg) cfg benches (allBenchmarks value env)
4443 where
4544
46− allBenchmarks size = Prelude.concat
45+ allBenchmarks size env = Prelude.concat
4746 [ Generation.benchmarks moduleName size
4847 , Elimination.benchmarks moduleName size
48+ , Exceptions.benchmarks moduleName env
49+ , Split.benchmarks moduleName env
4950 , Transformation1.benchmarks moduleName size
5051 , Transformation2.benchmarks moduleName size
5152 , Transformation3.benchmarks moduleName size
benchmark/Streamly/Benchmark/Prelude/Serial/Exceptions.hs+15−14
@@ -18,9 +18,7 @@
1818{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
1919#endif
2020
21−module Serial.Exceptions
22− (allBenchmarks)
23−where
21+module Serial.Exceptions (benchmarks) where
2422
2523import Control.Exception (SomeException)
2624import System.IO (Handle, hClose, hPutChar)
@@ -33,7 +31,8 @@ import qualified Streamly.Prelude as S
3331
3432import Gauge hiding (env)
3533import Prelude hiding (last, length)
36−import Streamly.Benchmark.CommonH
34+import Streamly.Benchmark.Common
35+import Streamly.Benchmark.Common.Handle
3736
3837#ifdef INSPECTION
3938import Test.Inspection
@@ -104,7 +103,7 @@ readWriteAfter_Stream inh devNull =
104103
105104o_1_space_copy_stream_exceptions :: BenchEnv -> [Benchmark]
106105o_1_space_copy_stream_exceptions env =
107− [ bgroup "copy/read/exceptions"
106+ [ bgroup "exceptions"
108107 [ mkBenchSmall "S.onException" env $ \inh _ ->
109108 readWriteOnExceptionStream inh (nullH env)
110109 , mkBenchSmall "S.handle" env $ \inh _ ->
@@ -120,7 +119,7 @@ o_1_space_copy_stream_exceptions env =
120119 , mkBenchSmall "S.after_" env $ \inh _ ->
121120 readWriteAfter_Stream inh (nullH env)
122121 ]
123− , bgroup "copy/fromToBytes/exceptions"
122+ , bgroup "exceptions/fromToBytes"
124123 [ mkBenchSmall "S.bracket_" env $ \inh _ ->
125124 fromToBytesBracket_Stream inh (nullH env)
126125 , mkBenchSmall "S.bracket" env $ \inh _ ->
@@ -161,7 +160,7 @@ readChunksBracket inh devNull =
161160
162161o_1_space_copy_exceptions_readChunks :: BenchEnv -> [Benchmark]
163162o_1_space_copy_exceptions_readChunks env =
164− [ bgroup "copy/readChunks/exceptions"
163+ [ bgroup "exceptions/readChunks"
165164 [ mkBench "UF.onException" env $ \inH _ ->
166165 readChunksOnException inH (nullH env)
167166 , mkBench "UF.bracket_" env $ \inH _ ->
@@ -199,7 +198,7 @@ toChunksBracket inh devNull =
199198
200199o_1_space_copy_exceptions_toChunks :: BenchEnv -> [Benchmark]
201200o_1_space_copy_exceptions_toChunks env =
202− [ bgroup "copy/toChunks/exceptions"
201+ [ bgroup "exceptions/toChunks"
203202 [ mkBench "S.bracket_" env $ \inH _ ->
204203 toChunksBracket_ inH (nullH env)
205204 , mkBench "S.bracket" env $ \inH _ ->
@@ -208,9 +207,11 @@ o_1_space_copy_exceptions_toChunks env =
208207 ]
209208
210209
211−allBenchmarks :: BenchEnv -> [Benchmark]
212−allBenchmarks env = Prelude.concat
213− [ o_1_space_copy_exceptions_readChunks env
214− , o_1_space_copy_exceptions_toChunks env
215− , o_1_space_copy_stream_exceptions env
216− ]
210+benchmarks :: String -> BenchEnv -> [Benchmark]
211+benchmarks moduleName env =
212+ [ bgroup (o_1_space_prefix moduleName) $ concat
213+ [ o_1_space_copy_exceptions_readChunks env
214+ , o_1_space_copy_exceptions_toChunks env
215+ , o_1_space_copy_stream_exceptions env
216+ ]
217+ ]
benchmark/Streamly/Benchmark/Prelude/Serial/Split.hs+15−14
@@ -1,8 +1,7 @@
11 -- |
2−-- Module : Streamly.Benchmark.Prelude.System.Split
2+-- Module : Streamly.Benchmark.Prelude.Serial.Split
33-- Copyright : (c) 2019 Composewell Technologies
4−--
5−-- License : BSD3
4+-- License : BSD-3-Clause
65-- Maintainer : streamly@composewell.com
76-- Stability : experimental
87-- Portability : GHC
@@ -19,9 +18,7 @@
1918{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
2019#endif
2120
22−module Serial.Split
23− (allBenchmarks)
24−where
21+module Serial.Split (benchmarks) where
2522
2623import Data.Char (ord)
2724import Data.Word (Word8)
@@ -38,7 +35,8 @@ import qualified Streamly.Prelude as S
3835
3936import Gauge hiding (env)
4037import Prelude hiding (last, length)
41−import Streamly.Benchmark.CommonH
38+import Streamly.Benchmark.Common
39+import Streamly.Benchmark.Common.Handle
4240
4341#ifdef INSPECTION
4442import Streamly.Internal.Data.Stream.StreamD.Type (Step(..))
@@ -147,7 +145,7 @@ splitOnSuffixSeq str inh =
147145
148146o_1_space_reduce_read_split :: BenchEnv -> [Benchmark]
149147o_1_space_reduce_read_split env =
150− [ bgroup "reduce/read"
148+ [ bgroup "split"
151149 [ mkBench "S.parseMany (PR.sliceSepBy (== lf) FL.drain)" env
152150 $ \inh _ -> parseManySepBy inh
153151 , mkBench "S.wordsBy isSpace FL.drain" env $ \inh _ ->
@@ -200,7 +198,7 @@ splitOnSeqUtf8 str inh =
200198
201199o_1_space_reduce_toChunks_split :: BenchEnv -> [Benchmark]
202200o_1_space_reduce_toChunks_split env =
203− [ bgroup "reduce/toChunks"
201+ [ bgroup "split/toChunks"
204202 [ mkBenchSmall ("S.splitOnSeqUtf8 \"abcdefgh\" FL.drain "
205203 ++ ". US.decodeUtf8Arrays") env $ \inh _ ->
206204 splitOnSeqUtf8 "abcdefgh" inh
@@ -208,9 +206,12 @@ o_1_space_reduce_toChunks_split env =
208206 env $ \inh _ -> splitOnSeqUtf8 "abcdefghijklmnopqrstuvwxyz" inh
209207 ]
210208 ]
211−allBenchmarks :: BenchEnv -> [Benchmark]
212−allBenchmarks env = Prelude.concat
213− [ o_1_space_reduce_read_split env
214− , o_1_space_reduce_toChunks_split env
215− ]
209+
210+benchmarks :: String -> BenchEnv -> [Benchmark]
211+benchmarks moduleName env =
212+ [ bgroup (o_1_space_prefix moduleName) $ concat
213+ [ o_1_space_reduce_read_split env
214+ , o_1_space_reduce_toChunks_split env
215+ ]
216+ ]
216217
benchmark/Streamly/Benchmark/Unicode/Stream.hs+7−8
@@ -1,8 +1,7 @@
11-- |
22-- Module : Streamly.Unicode.Stream
33-- Copyright : (c) 2019 Composewell Technologies
4−--
5−-- License : BSD3
4+-- License : BSD-3-Clause
65-- Maintainer : streamly@composewell.com
76-- Stability : experimental
87-- Portability : GHC
@@ -19,8 +18,8 @@
1918{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
2019#endif
2120
22−import System.IO (Handle)
2321import Prelude hiding (last, length)
22+import System.IO (Handle)
2423
2524import qualified Streamly.Data.Fold as FL
2625import qualified Streamly.Unicode.Stream as SS
@@ -34,8 +33,8 @@ import qualified Streamly.Data.Array.Storable.Foreign as A
3433import qualified Streamly.Prelude as S
3534
3635import Gauge hiding (env)
37−import Streamly.Benchmark.CommonH
3836import Streamly.Benchmark.Common
37+import Streamly.Benchmark.Common.Handle
3938
4039#ifdef INSPECTION
4140import Foreign.Storable (Storable)
@@ -65,7 +64,7 @@ inspect $ hasNoTypeClasses 'copyCodecUtf8ArraysLenient
6564
6665o_1_space_copy_chunked :: BenchEnv -> [Benchmark]
6766o_1_space_copy_chunked env =
68− [ bgroup "copy/toChunks"
67+ [ bgroup "decode-encode/toChunks"
6968 [
7069 mkBenchSmall "decodeEncodeUtf8Lenient" env $ \inH outH ->
7170 copyCodecUtf8ArraysLenient inH outH
@@ -169,7 +168,7 @@ wordsUnwordsCharArrayCopy inh outh =
169168
170169o_1_space_copy_read_group_ungroup :: BenchEnv -> [Benchmark]
171170o_1_space_copy_read_group_ungroup env =
172− [ bgroup "copy/read/group-ungroup"
171+ [ bgroup "ungroup-group"
173172 [ mkBenchSmall "US.unlines . S.splitOnSuffix ([Word8])" env
174173 $ \inh outh -> linesUnlinesCopy inh outh
175174 , mkBenchSmall "S.interposeSuffix . S.splitOnSuffix(Array Word8)" env
@@ -256,7 +255,7 @@ inspect $ hasNoTypeClasses 'copyStreamUtf8
256255
257256o_1_space_copy_read :: BenchEnv -> [Benchmark]
258257o_1_space_copy_read env =
259− [ bgroup "copy/read"
258+ [ bgroup "decode-encode"
260259 [
261260 -- This needs an ascii file, as decode just errors out.
262261 mkBench "SS.encodeLatin1' . SS.decodeLatin1" env $ \inh outh ->
@@ -275,7 +274,7 @@ o_1_space_copy_read env =
275274main :: IO ()
276275main = do
277276 (_, cfg, benches) <- parseCLIOpts defaultStreamSize
278− env <- mkBenchEnv "Benchmark_FileSystem_Handle_InputFile"
277+ env <- mkHandleBenchEnv
279278 runMode (mode cfg) cfg benches (allBenchmarks env)
280279
281280 where
benchmark/Streamly/Benchmark/CommonH.hs → benchmark/lib/Streamly/Benchmark/Common/Handle.hsrenamed+11−14
@@ -1,8 +1,7 @@
11-- |
2−-- Module : Streamly.Benchmark.FileSystem.Handle
2+-- Module : Streamly.Benchmark.Common.Handle
33-- Copyright : (c) 2019 Composewell Technologies
4−--
5−-- License : BSD3
4+-- License : BSD-3-Clause
65-- Maintainer : streamly@composewell.com
76-- Stability : experimental
87-- Portability : GHC
@@ -19,7 +18,7 @@
1918{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
2019#endif
2120
22−module Streamly.Benchmark.CommonH
21+module Streamly.Benchmark.Common.Handle
2322 ( BenchEnv (..)
2423 , RefHandles (..)
2524 , scratchDir
@@ -30,23 +29,22 @@ module Streamly.Benchmark.CommonH
3029 , mkBenchSmall
3130 , isSpace
3231 , isSp
33− , mkBenchEnv
32+ , mkHandleBenchEnv
3433 )
3534where
3635
3736import Control.DeepSeq (NFData(rnf))
3837import Data.Char (ord, chr)
3938import Data.Word (Word8)
39+import System.Directory (getFileSize)
40+import System.Environment (lookupEnv)
4041import System.IO (openFile, IOMode(..), Handle, hClose)
42+import System.Process.Typed (shell, runProcess_)
4143
4244import Data.IORef
45+import Prelude hiding (last, length)
4346import Gauge hiding (env)
4447
45−import System.Directory (getFileSize)
46−import System.Environment (lookupEnv)
47−-- import System.IO (openFile, IOMode(..))
48−import System.Process.Typed (shell, runProcess_)
49−import Prelude hiding (last, length)
5048
5149scratchDir :: String
5250scratchDir = "benchmark-tmp/"
@@ -166,10 +164,9 @@ smallFileSize = 10 * 1024 * 1024
166164bigFileSize :: Int
167165bigFileSize = 100 * 1024 * 1024
168166
169−-- Function to create a BenchEnv
170−mkBenchEnv :: String -> IO BenchEnv
171−mkBenchEnv envName = do
172− r <- lookupEnv envName
167+mkHandleBenchEnv :: IO BenchEnv
168+mkHandleBenchEnv = do
169+ r <- lookupEnv "Benchmark_FileSystem_Handle_InputFile"
173170 (small, big) <-
174171 case r of
175172 Just inFileName -> return (inFileName, inFileName)
benchmark/streamly-benchmarks.cabal+6−6
@@ -130,7 +130,12 @@ library
130130 import: lib-options, bench-depends
131131 hs-source-dirs: lib
132132 exposed-modules: Streamly.Benchmark.Common
133+ , Streamly.Benchmark.Common.Handle
133134 , Streamly.Benchmark.Prelude
135+ build-depends:
136+ typed-process >= 0.2.3 && < 0.3
137+ , directory >= 1.2.2 && < 1.4
138+ , ghc-prim >= 0.4 && < 0.7
134139
135140-------------------------------------------------------------------------------
136141-- Benchmarks
@@ -167,7 +172,6 @@ benchmark Prelude.Serial
167172 , Serial.Nested
168173 , Serial.Exceptions
169174 , Serial.Split
170− , Streamly.Benchmark.CommonH
171175 ghc-options: +RTS -M1000M -RTS
172176 if impl(ghcjs)
173177 buildable: False
@@ -256,8 +260,7 @@ benchmark Data.Unfold
256260 type: exitcode-stdio-1.0
257261 hs-source-dirs: .
258262 main-is: Streamly/Benchmark/Data/Unfold.hs
259− other-modules: Streamly.Benchmark.Data.NestedUnfoldOps
260− , Streamly.Benchmark.CommonH
263+ other-modules: Streamly.Benchmark.Data.NestedUnfoldOps
261264 if impl(ghcjs)
262265 buildable: False
263266 else
@@ -457,7 +460,6 @@ benchmark FileSystem.Handle
457460 other-modules:
458461 Handle.Read
459462 , Handle.ReadWrite
460− , Streamly.Benchmark.CommonH
461463 build-depends:
462464 typed-process >= 0.2.3 && < 0.3
463465 , directory >= 1.2.2 && < 1.4
@@ -471,8 +473,6 @@ benchmark Unicode.Stream
471473 type: exitcode-stdio-1.0
472474 hs-source-dirs: . Streamly/Benchmark/Unicode
473475 main-is: Stream.hs
474− other-modules:
475− Streamly.Benchmark.CommonH
476476 build-depends:
477477 typed-process >= 0.2.3 && < 0.3
478478 , directory >= 1.2.2 && < 1.4
streamly.cabal+1−1
@@ -109,7 +109,6 @@ extra-source-files:
109109 bench.sh
110110 benchmark/*.hs
111111 benchmark/README.md
112− benchmark/Streamly/Benchmark/CommonH.hs
113112 benchmark/Streamly/Benchmark/Data/*.hs
114113 benchmark/Streamly/Benchmark/Data/Parser/*.hs
115114 benchmark/Streamly/Benchmark/Data/Stream/*.hs
@@ -119,6 +118,7 @@ extra-source-files:
119118 benchmark/Streamly/Benchmark/Prelude/Serial/*.hs
120119 benchmark/Streamly/Benchmark/Unicode/*.hs
121120 benchmark/lib/Streamly/Benchmark/*.hs
121+ benchmark/lib/Streamly/Benchmark/Common/*.hs
122122 benchmark/streamly-benchmarks.cabal
123123 bin/bench-exec-one.sh
124124 bin/mk-hscope.sh