on master help sign in
Add benchmarks for a few functions in FileSystem.Handle

Benchmarks added: - write . read - write - read - writeWithBufferOf . readWithBufferOf - readWithBufferOf - writeWithBufferOf - fromBytes . readWithBufferOf - readWithBufferOf - write . readChunks (Commented) - readChunks - write . writeChunks (Commented) - writeChunks

commitc7b7c2a4237eb6c830cd8a737d58321b448208b2 authoradithyaov <adithya@composewell.com> dateMon 23 Nov 2020, 12:43 (6 years ago) parent7bb8512
1 file changed+83
benchmark/Streamly/Benchmark/FileSystem/Handle/ReadWrite.hs+83
benchmark/Streamly/Benchmark/FileSystem/Handle/ReadWrite.hs+83
@@ -26,6 +26,7 @@ where
2626import Control.Exception (SomeException)
2727import System.IO (Handle, hClose, hPutChar)
2828import Prelude hiding (last, length)
29+import Streamly.Internal.Data.Array.Storable.Foreign.Types (defaultChunkSize)
2930
3031import qualified Streamly.Data.Fold as FL
3132import qualified Streamly.Unicode.Stream as SS
@@ -291,11 +292,92 @@ inspect $ 'readFromBytesNull `hasNoType` ''AT.ArrayUnsafe -- FH.fromBytes/S.arra
291292inspect $ 'readFromBytesNull `hasNoType` ''D.GroupState
292293#endif
293294
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+
294330o_1_space_copy_fromBytes :: BenchEnv -> [Benchmark]
295331o_1_space_copy_fromBytes env =
296332 [ bgroup "copy/fromBytes"
297333 [ mkBench "rawToNull" env $ \inh _ ->
298334 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)
299381 ]
300382 ]
301383
@@ -631,6 +713,7 @@ allBenchmarks env = Prelude.concat
631713 , o_1_space_copy_exceptions_toChunks env
632714 , o_1_space_copy_read env
633715 , o_1_space_copy_fromBytes env
716+ , o_1_space_copy env
634717 , o_1_space_copy_read_exceptions env
635718 , o_1_space_copy_stream_exceptions env
636719 , o_1_space_copy_toChunks_group_ungroup env