on master help sign in
Add benchmarks for a few functions in FileSystem.Handle
c7b7c2aadithyaov
benchmark/Streamly/Benchmark/FileSystem/Handle/ReadWrite.hs+83
@@ -26,6 +26,7 @@ where
26import Control.Exception (SomeException)
26import Control.Exception (SomeException)
27import System.IO (Handle, hClose, hPutChar)
27import System.IO (Handle, hClose, hPutChar)
28import Prelude hiding (last, length)
28import Prelude hiding (last, length)
29+import Streamly.Internal.Data.Array.Storable.Foreign.Types (defaultChunkSize)
29
30
30import qualified Streamly.Data.Fold as FL
31import qualified Streamly.Data.Fold as FL
31import qualified Streamly.Unicode.Stream as SS
32import qualified Streamly.Unicode.Stream as SS
@@ -291,11 +292,92 @@ inspect $ 'readFromBytesNull `hasNoType` ''AT.ArrayUnsafe -- FH.fromBytes/S.arra
291inspect $ 'readFromBytesNull `hasNoType` ''D.GroupState
292inspect $ 'readFromBytesNull `hasNoType` ''D.GroupState
292#endif
293#endif
293
294
295+-- | Send the file contents ('defaultChunkSize') to /dev/null
296+readWithBufferOfFromBytesNull :: Handle -> Handle -> IO ()
297+readWithBufferOfFromBytesNull inh devNull =
298+ IFH.fromBytes devNull
299+ $ S.unfold FH.readWithBufferOf (defaultChunkSize, inh)
300+
301+#ifdef INSPECTION
302+inspect $ hasNoTypeClasses 'readWithBufferOfFromBytesNull
303+inspect $ 'readWithBufferOfFromBytesNull `hasNoType` ''Step
304+inspect $ 'readWithBufferOfFromBytesNull `hasNoType` ''AT.SpliceState
305+inspect $ 'readWithBufferOfFromBytesNull `hasNoType` ''AT.ArrayUnsafe -- FH.fromBytes/S.arraysOf
306+inspect $ 'readWithBufferOfFromBytesNull `hasNoType` ''D.GroupState
307+#endif
308+
309+-- | Send the chunk content ('defaultChunkSize') to /dev/null
310+-- Implicitly benchmarked via 'readFromBytesNull'
311+_readChunks :: Handle -> Handle -> IO ()
312+_readChunks inh devNull = IUF.fold unf fld inh
313+
314+ where
315+
316+ fld = FH.write devNull
317+ unf = IUF.concat FH.readChunks A.read
318+
319+-- | Send the chunk content to /dev/null
320+-- Implicitly benchmarked via 'readWithBufferOfFromBytesNull'
321+_readChunksWithBufferOf :: Handle -> Handle -> IO ()
322+_readChunksWithBufferOf inh devNull = IUF.fold unf fld (defaultChunkSize, inh)
323+
324+ where
325+
326+ fld = FH.write devNull
327+ unf = IUF.concat FH.readChunksWithBufferOf A.read
328+
329+
294o_1_space_copy_fromBytes :: BenchEnv -> [Benchmark]
330o_1_space_copy_fromBytes :: BenchEnv -> [Benchmark]
295o_1_space_copy_fromBytes env =
331o_1_space_copy_fromBytes env =
296 [ bgroup "copy/fromBytes"
332 [ bgroup "copy/fromBytes"
297 [ mkBench "rawToNull" env $ \inh _ ->
333 [ mkBench "rawToNull" env $ \inh _ ->
298 readFromBytesNull inh (nullH env)
334 readFromBytesNull inh (nullH env)
335+ , mkBench "FH.readWithBufferOf" env $ \inh _ ->
336+ readWithBufferOfFromBytesNull inh (nullH env)
337+ ]
338+ ]
339+
340+-- | Send the file contents ('defaultChunkSize') to /dev/null
341+writeReadWithBufferOf :: Handle -> Handle -> IO ()
342+writeReadWithBufferOf inh devNull = IUF.fold unf fld (defaultChunkSize, inh)
343+
344+ where
345+
346+ fld = FH.writeWithBufferOf defaultChunkSize devNull
347+ unf = FH.readWithBufferOf
348+
349+#ifdef INSPECTION
350+inspect $ hasNoTypeClasses 'writeReadWithBufferOf
351+inspect $ 'writeReadWithBufferOf `hasNoType` ''Step
352+inspect $ 'writeReadWithBufferOf `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
353+inspect $ 'writeReadWithBufferOf `hasNoType` ''A.ReadUState -- FH.read/A.read
354+inspect $ 'writeReadWithBufferOf `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
355+#endif
356+
357+-- | Send the file contents ('AT.defaultChunkSize') to /dev/null
358+writeRead :: Handle -> Handle -> IO ()
359+writeRead inh devNull = IUF.fold unf fld inh
360+
361+ where
362+
363+ fld = FH.write devNull
364+ unf = FH.read
365+
366+#ifdef INSPECTION
367+inspect $ hasNoTypeClasses 'writeRead
368+inspect $ 'writeRead `hasNoType` ''Step
369+inspect $ 'writeRead `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
370+inspect $ 'writeRead `hasNoType` ''A.ReadUState -- FH.read/A.read
371+inspect $ 'writeRead `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
372+#endif
373+
374+o_1_space_copy :: BenchEnv -> [Benchmark]
375+o_1_space_copy env =
376+ [ bgroup "copy"
377+ [ mkBench "FH.write . FH.read" env $ \inh _ ->
378+ writeRead inh (nullH env)
379+ , mkBench "FH.writeWithBufferOf . FH.readWithBufferOf" env $ \inh _ ->
380+ writeReadWithBufferOf inh (nullH env)
299 ]
381 ]
300 ]
382 ]
301
383
@@ -631,6 +713,7 @@ allBenchmarks env = Prelude.concat
631 , o_1_space_copy_exceptions_toChunks env
713 , o_1_space_copy_exceptions_toChunks env
632 , o_1_space_copy_read env
714 , o_1_space_copy_read env
633 , o_1_space_copy_fromBytes env
715 , o_1_space_copy_fromBytes env
716+ , o_1_space_copy env
634 , o_1_space_copy_read_exceptions env
717 , o_1_space_copy_read_exceptions env
635 , o_1_space_copy_stream_exceptions env
718 , o_1_space_copy_stream_exceptions env
636 , o_1_space_copy_toChunks_group_ungroup env
719 , o_1_space_copy_toChunks_group_ungroup env