2-- Module : Streamly.Benchmark.FileSystem.Handle
3-- Copyright : (c) 2019 Composewell Technologies
4-- License : BSD3-3-Clause
5-- Maintainer : streamly@composewell.com
6-- Stability : experimental
10{-# LANGUAGE ScopedTypeVariables #-}
12#ifdef __HADDOCK_VERSION__
17{-# LANGUAGE TemplateHaskell #-}
18{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
21module Handle.ReadWrite
25import System.IO (Handle)
26import Prelude hiding (last, length)
27import Streamly.Internal.System.IO (defaultChunkSize)
29import qualified Streamly.FileSystem.Handle as FH
30import qualified Streamly.Internal.Data.Unfold as IUF
31import qualified Streamly.Internal.FileSystem.Handle as IFH
32import qualified Streamly.Data.Array.Unboxed as A
33import qualified Streamly.Prelude as S
35import Gauge hiding (env)
36import Streamly.Benchmark.Common.Handle
39import Streamly.Internal.Data.Stream.StreamD.Type (Step(..))
41import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
42import qualified Streamly.Internal.Data.Tuple.Strict as Strict
43import qualified Streamly.Internal.Data.Array.Unboxed.Mut.Stream as MAS
44import qualified Streamly.Internal.Data.Array.Unboxed.Type as AT
49-------------------------------------------------------------------------------
51-------------------------------------------------------------------------------
54copyChunks :: Handle -> Handle -> IO ()
55copyChunks inh outh = S.fold (IFH.writeChunks outh) $ IFH.getChunks inh
58inspect $ hasNoTypeClasses 'copyChunks
59inspect $ 'copyChunks `hasNoType` ''Step
62o_1_space_copy_chunked :: BenchEnv -> [Benchmark]
63o_1_space_copy_chunked env =
64 [ bgroup "copy/getChunks"
65 [ mkBench "toNull" env $ \inH _ ->
66 copyChunks inH (nullH env)
67 , mkBench "raw" env $ \inH outH ->
72-------------------------------------------------------------------------------
74-------------------------------------------------------------------------------
77copyStream :: Handle -> Handle -> IO ()
78copyStream inh outh = S.fold (FH.write outh) (S.unfold FH.read inh)
81inspect $ hasNoTypeClasses 'copyStream
82inspect $ 'copyStream `hasNoType` ''Step -- S.unfold
83inspect $ 'copyStream `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
84inspect $ 'copyStream `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
86inspect $ 'copyStream `hasNoType` ''Strict.Tuple3' -- FH.write/chunksOf
89o_1_space_copy_read :: BenchEnv -> [Benchmark]
90o_1_space_copy_read env =
92 [ mkBench "rawToNull" env $ \inh _ ->
93 copyStream inh (nullH env)
94 , mkBench "rawToFile" env $ \inh outh ->
99-------------------------------------------------------------------------------
101-------------------------------------------------------------------------------
103-- | Send the file contents to /dev/null
104readFromBytesNull :: Handle -> Handle -> IO ()
105readFromBytesNull inh devNull = IFH.putBytes devNull $ S.unfold FH.read inh
108inspect $ hasNoTypeClasses 'readFromBytesNull
109inspect $ 'readFromBytesNull `hasNoType` ''Step
110inspect $ 'readFromBytesNull `hasNoType` ''MAS.SpliceState
111inspect $ 'readFromBytesNull `hasNoType` ''AT.ArrayUnsafe -- FH.fromBytes/S.arraysOf
112inspect $ 'readFromBytesNull `hasNoType` ''D.FoldMany
115-- | Send the file contents ('defaultChunkSize') to /dev/null
116readWithFromBytesNull :: Handle -> Handle -> IO ()
117readWithFromBytesNull inh devNull =
119 $ S.unfold FH.readWith (defaultChunkSize, inh)
122inspect $ hasNoTypeClasses 'readWithFromBytesNull
123inspect $ 'readWithFromBytesNull `hasNoType` ''Step
124inspect $ 'readWithFromBytesNull `hasNoType` ''MAS.SpliceState
125inspect $ 'readWithFromBytesNull `hasNoType` ''AT.ArrayUnsafe -- FH.fromBytes/S.arraysOf
126inspect $ 'readWithFromBytesNull `hasNoType` ''D.FoldMany
129-- | Send the chunk content ('defaultChunkSize') to /dev/null
130-- Implicitly benchmarked via 'readFromBytesNull'
131_readChunks :: Handle -> Handle -> IO ()
132_readChunks inh devNull = IUF.fold fld unf inh
136 fld = FH.write devNull
137 unf = IUF.many A.read FH.readChunks
139-- | Send the chunk content to /dev/null
140-- Implicitly benchmarked via 'readWithFromBytesNull'
141_readChunksWith :: Handle -> Handle -> IO ()
142_readChunksWith inh devNull = IUF.fold fld unf (defaultChunkSize, inh)
146 fld = FH.write devNull
147 unf = IUF.many A.read FH.readChunksWith
149o_1_space_copy_fromBytes :: BenchEnv -> [Benchmark]
150o_1_space_copy_fromBytes env =
151 [ bgroup "copy/putBytes"
152 [ mkBench "rawToNull" env $ \inh _ ->
153 readFromBytesNull inh (nullH env)
154 , mkBench "FH.readWith" env $ \inh _ ->
155 readWithFromBytesNull inh (nullH env)
159-- | Send the file contents ('defaultChunkSize') to /dev/null
160writeReadWith :: Handle -> Handle -> IO ()
161writeReadWith inh devNull = IUF.fold fld unf (defaultChunkSize, inh)
165 fld = FH.writeWith defaultChunkSize devNull
169inspect $ hasNoTypeClasses 'writeReadWith
170inspect $ 'writeReadWith `hasNoType` ''Step
171inspect $ 'writeReadWith `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
172inspect $ 'writeReadWith `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
176-- | Send the file contents ('AT.defaultChunkSize') to /dev/null
177writeRead :: Handle -> Handle -> IO ()
178writeRead inh devNull = IUF.fold fld unf inh
182 fld = FH.write devNull
186inspect $ hasNoTypeClasses 'writeRead
187inspect $ 'writeRead `hasNoType` ''Step
188inspect $ 'writeRead `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
189inspect $ 'writeRead `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
193o_1_space_copy :: BenchEnv -> [Benchmark]
196 [ mkBench "FH.write . FH.read" env $ \inh _ ->
197 writeRead inh (nullH env)
198 , mkBench "FH.writeWith . FH.readWith" env $ \inh _ ->
199 writeReadWith inh (nullH env)
203-------------------------------------------------------------------------------
205-------------------------------------------------------------------------------
207allBenchmarks :: BenchEnv -> [Benchmark]
208allBenchmarks env = Prelude.concat
209 [ o_1_space_copy_chunked env
210 , o_1_space_copy_read env
211 , o_1_space_copy_fromBytes env
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list