1{-# OPTIONS_GHC -Wno-deprecations #-}
4-- Module : Streamly.Benchmark.FileSystem.Handle
5-- Copyright : (c) 2019 Composewell Technologies
6-- License : BSD3-3-Clause
7-- Maintainer : streamly@composewell.com
8-- Stability : experimental
12{-# LANGUAGE ScopedTypeVariables #-}
14#ifdef __HADDOCK_VERSION__
19{-# LANGUAGE TemplateHaskell #-}
20{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
23module Handle.ReadWrite
27import System.IO (Handle)
28import Prelude hiding (last, length)
29import Streamly.Internal.System.IO (defaultChunkSize)
31import qualified Streamly.FileSystem.Handle as FH
32import qualified Streamly.Internal.Data.Unfold as IUF
33import qualified Streamly.Internal.FileSystem.Handle as IFH
34import qualified Streamly.Data.Array as A
35import qualified Streamly.Data.Stream.Prelude as S
37import Test.Tasty.Bench hiding (env)
38import Streamly.Benchmark.Common.Handle
41import Streamly.Internal.Data.Stream (Step(..))
43import qualified Streamly.Internal.Data.Stream as D
44import qualified Streamly.Internal.Data.Tuple.Strict as Strict
45import qualified Streamly.Internal.Data.MutArray.Stream as MAS
46import qualified Streamly.Internal.Data.Array as AT
51-------------------------------------------------------------------------------
53-------------------------------------------------------------------------------
56copyChunks :: Handle -> Handle -> IO ()
57copyChunks inh outh = S.fold (IFH.writeChunks outh) $ IFH.readChunks inh
60inspect $ hasNoTypeClasses 'copyChunks
61inspect $ 'copyChunks `hasNoType` ''Step
64o_1_space_copy_chunked :: BenchEnv -> [Benchmark]
65o_1_space_copy_chunked env =
66 [ bgroup "copy/getChunks"
67 [ mkBench "toNull" env $ \inH _ ->
68 copyChunks inH (nullH env)
69 , mkBench "raw" env $ \inH outH ->
74-------------------------------------------------------------------------------
76-------------------------------------------------------------------------------
79copyStream :: Handle -> Handle -> IO ()
80copyStream inh outh = S.fold (FH.write outh) (S.unfold FH.reader inh)
83inspect $ hasNoTypeClasses 'copyStream
84inspect $ 'copyStream `hasNoType` ''Step -- S.unfold
85inspect $ 'copyStream `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
86inspect $ 'copyStream `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
88inspect $ 'copyStream `hasNoType` ''Strict.Tuple3' -- FH.write/chunksOf
91o_1_space_copy_read :: BenchEnv -> [Benchmark]
92o_1_space_copy_read env =
94 [ mkBench "rawToNull" env $ \inh _ ->
95 copyStream inh (nullH env)
96 , mkBench "rawToFile" env $ \inh outh ->
101-------------------------------------------------------------------------------
103-------------------------------------------------------------------------------
105-- | Send the file contents to /dev/null
106readFromBytesNull :: Handle -> Handle -> IO ()
107readFromBytesNull inh devNull = IFH.putBytes devNull $ S.unfold FH.reader inh
110inspect $ hasNoTypeClasses 'readFromBytesNull
111inspect $ 'readFromBytesNull `hasNoType` ''Step
112inspect $ 'readFromBytesNull `hasNoType` ''MAS.SpliceState
113inspect $ 'readFromBytesNull `hasNoType` ''AT.ArrayUnsafe -- FH.fromBytes/S.chunksOf
114inspect $ 'readFromBytesNull `hasNoType` ''D.FoldMany
117-- | Send the file contents ('defaultChunkSize') to /dev/null
118readWithFromBytesNull :: Handle -> Handle -> IO ()
119readWithFromBytesNull inh devNull =
121 $ S.unfold FH.readerWith (defaultChunkSize, inh)
124inspect $ hasNoTypeClasses 'readWithFromBytesNull
125inspect $ 'readWithFromBytesNull `hasNoType` ''Step
126inspect $ 'readWithFromBytesNull `hasNoType` ''MAS.SpliceState
127inspect $ 'readWithFromBytesNull `hasNoType` ''AT.ArrayUnsafe -- FH.fromBytes/S.chunksOf
128inspect $ 'readWithFromBytesNull `hasNoType` ''D.FoldMany
131-- | Send the chunk content ('defaultChunkSize') to /dev/null
132-- Implicitly benchmarked via 'readFromBytesNull'
133_readChunks :: Handle -> Handle -> IO ()
134_readChunks inh devNull = IUF.fold fld unf inh
138 fld = FH.write devNull
139 unf = IUF.many A.reader FH.chunkReader
141-- | Send the chunk content to /dev/null
142-- Implicitly benchmarked via 'readWithFromBytesNull'
143_readChunksWith :: Handle -> Handle -> IO ()
144_readChunksWith inh devNull = IUF.fold fld unf (defaultChunkSize, inh)
148 fld = FH.write devNull
149 unf = IUF.many A.reader FH.chunkReaderWith
151o_1_space_copy_fromBytes :: BenchEnv -> [Benchmark]
152o_1_space_copy_fromBytes env =
153 [ bgroup "copy/putBytes"
154 [ mkBench "rawToNull" env $ \inh _ ->
155 readFromBytesNull inh (nullH env)
156 , mkBench "FH.readWith" env $ \inh _ ->
157 readWithFromBytesNull inh (nullH env)
161-- | Send the file contents ('defaultChunkSize') to /dev/null
162writeReadWith :: Handle -> Handle -> IO ()
163writeReadWith inh devNull = IUF.fold fld unf (defaultChunkSize, inh)
167 fld = FH.writeWith defaultChunkSize devNull
171inspect $ hasNoTypeClasses 'writeReadWith
172inspect $ 'writeReadWith `hasNoType` ''Step
173inspect $ 'writeReadWith `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
174inspect $ 'writeReadWith `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
178-- | Send the file contents ('AT.defaultChunkSize') to /dev/null
179writeRead :: Handle -> Handle -> IO ()
180writeRead inh devNull = IUF.fold fld unf inh
184 fld = FH.write devNull
188inspect $ hasNoTypeClasses 'writeRead
189inspect $ 'writeRead `hasNoType` ''Step
190inspect $ 'writeRead `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
191inspect $ 'writeRead `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
195o_1_space_copy :: BenchEnv -> [Benchmark]
198 [ mkBench "FH.write . FH.read" env $ \inh _ ->
199 writeRead inh (nullH env)
200 , mkBench "FH.writeWith . FH.readWith" env $ \inh _ ->
201 writeReadWith inh (nullH env)
205-------------------------------------------------------------------------------
207-------------------------------------------------------------------------------
209allBenchmarks :: BenchEnv -> [Benchmark]
210allBenchmarks env = Prelude.concat
211 [ o_1_space_copy_chunked env
212 , o_1_space_copy_read env
213 , 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