@@ -41,7 +41,8 @@ import qualified Streamly.Data.Array.Storable.Foreign as A
4141import qualified Streamly.Prelude as S
4242
4343import Gauge hiding (env)
44−import Handle.Common
44+-- import Handle.Common
45+import Streamly.Benchmark.CommonH
4546
4647#ifdef INSPECTION
4748import Foreign.Storable (Storable)
@@ -93,87 +94,6 @@ o_1_space_copy_chunked env =
9394 ]
9495 ]
9596
96−-- TBD reading with unfold
97−
98−-------------------------------------------------------------------------------
99−-- Exceptions readChunks
100−-------------------------------------------------------------------------------
101−
102−-- | Send the file contents to /dev/null with exception handling
103−readChunksOnException :: Handle -> Handle -> IO ()
104−readChunksOnException inh devNull =
105− let readEx = IUF.onException (\_ -> hClose inh) FH.readChunks
106− in IUF.fold readEx (IFH.writeChunks devNull) inh
107−
108−#ifdef INSPECTION
109−inspect $ hasNoTypeClasses 'readChunksOnException
110−-- inspect $ 'readChunksOnException `hasNoType` ''Step
111−#endif
112−
113−-- | Send the file contents to /dev/null with exception handling
114−readChunksBracket_ :: Handle -> Handle -> IO ()
115−readChunksBracket_ inh devNull =
116− let readEx = IUF.bracket_ return (\_ -> hClose inh) FH.readChunks
117− in IUF.fold readEx (IFH.writeChunks devNull) inh
118−
119−#ifdef INSPECTION
120−inspect $ hasNoTypeClasses 'readChunksBracket_
121−-- inspect $ 'readChunksBracket `hasNoType` ''Step
122−#endif
123−
124−readChunksBracket :: Handle -> Handle -> IO ()
125−readChunksBracket inh devNull =
126− let readEx = IUF.bracket return (\_ -> hClose inh) FH.readChunks
127− in IUF.fold readEx (IFH.writeChunks devNull) inh
128−
129−o_1_space_copy_exceptions_readChunks :: BenchEnv -> [Benchmark]
130−o_1_space_copy_exceptions_readChunks env =
131− [ bgroup "copy/readChunks/exceptions"
132− [ mkBench "UF.onException" env $ \inH _ ->
133− readChunksOnException inH (nullH env)
134− , mkBench "UF.bracket_" env $ \inH _ ->
135− readChunksBracket_ inH (nullH env)
136− , mkBench "UF.bracket" env $ \inH _ ->
137− readChunksBracket inH (nullH env)
138− ]
139− ]
140−
141−-------------------------------------------------------------------------------
142−-- Exceptions toChunks
143−-------------------------------------------------------------------------------
144−
145−-- | Send the file contents to /dev/null with exception handling
146−toChunksBracket_ :: Handle -> Handle -> IO ()
147−toChunksBracket_ inh devNull =
148− let readEx = IP.bracket_
149− (return ())
150− (\_ -> hClose inh)
151− (\_ -> IFH.toChunks inh)
152− in S.fold (IFH.writeChunks devNull) $ readEx
153−
154−#ifdef INSPECTION
155−inspect $ hasNoTypeClasses 'toChunksBracket_
156−-- inspect $ 'toChunksBracket `hasNoType` ''Step
157−#endif
158−
159−toChunksBracket :: Handle -> Handle -> IO ()
160−toChunksBracket inh devNull =
161− let readEx = S.bracket
162− (return ())
163− (\_ -> hClose inh)
164− (\_ -> IFH.toChunks inh)
165− in S.fold (IFH.writeChunks devNull) $ readEx
166−
167−o_1_space_copy_exceptions_toChunks :: BenchEnv -> [Benchmark]
168−o_1_space_copy_exceptions_toChunks env =
169− [ bgroup "copy/toChunks/exceptions"
170− [ mkBench "S.bracket_" env $ \inH _ ->
171− toChunksBracket_ inH (nullH env)
172− , mkBench "S.bracket" env $ \inH _ ->
173− toChunksBracket inH (nullH env)
174− ]
175− ]
176−
17797-------------------------------------------------------------------------------
17898-- copy unfold
17999-------------------------------------------------------------------------------
@@ -383,185 +303,6 @@ o_1_space_copy env =
383303 ]
384304 ]
385305
386−-------------------------------------------------------------------------------
387−-- unfold exceptions
388−-------------------------------------------------------------------------------
389−
390−-- | Send the file contents to /dev/null with exception handling
391−{-# NOINLINE readWriteOnExceptionUnfold #-}
392−readWriteOnExceptionUnfold :: Handle -> Handle -> IO ()
393−readWriteOnExceptionUnfold inh devNull =
394− let readEx = IUF.onException (\_ -> hClose inh) FH.read
395− in S.fold (FH.write devNull) $ S.unfold readEx inh
396−
397−#ifdef INSPECTION
398−inspect $ hasNoTypeClasses 'readWriteOnExceptionUnfold
399−-- inspect $ 'readWriteOnExceptionUnfold `hasNoType` ''Step
400−#endif
401−
402−-- | Send the file contents to /dev/null with exception handling
403−{-# NOINLINE readWriteHandleExceptionUnfold #-}
404−readWriteHandleExceptionUnfold :: Handle -> Handle -> IO ()
405−readWriteHandleExceptionUnfold inh devNull =
406− let handler (_e :: SomeException) = hClose inh >> return 10
407− readEx = IUF.handle (IUF.singletonM handler) FH.read
408− in S.fold (FH.write devNull) $ S.unfold readEx inh
409−
410−#ifdef INSPECTION
411−inspect $ hasNoTypeClasses 'readWriteHandleExceptionUnfold
412−-- inspect $ 'readWriteHandleExceptionUnfold `hasNoType` ''Step
413−#endif
414−
415−-- | Send the file contents to /dev/null with exception handling
416−{-# NOINLINE readWriteFinally_Unfold #-}
417−readWriteFinally_Unfold :: Handle -> Handle -> IO ()
418−readWriteFinally_Unfold inh devNull =
419− let readEx = IUF.finally_ (\_ -> hClose inh) FH.read
420− in S.fold (FH.write devNull) $ S.unfold readEx inh
421−
422−#ifdef INSPECTION
423−inspect $ hasNoTypeClasses 'readWriteFinally_Unfold
424−-- inspect $ 'readWriteFinallyUnfold `hasNoType` ''Step
425−#endif
426−
427−{-# NOINLINE readWriteFinallyUnfold #-}
428−readWriteFinallyUnfold :: Handle -> Handle -> IO ()
429−readWriteFinallyUnfold inh devNull =
430− let readEx = IUF.finally (\_ -> hClose inh) FH.read
431− in S.fold (FH.write devNull) $ S.unfold readEx inh
432−
433−-- | Send the file contents to /dev/null with exception handling
434−{-# NOINLINE readWriteBracket_Unfold #-}
435−readWriteBracket_Unfold :: Handle -> Handle -> IO ()
436−readWriteBracket_Unfold inh devNull =
437− let readEx = IUF.bracket_ return (\_ -> hClose inh) FH.read
438− in S.fold (FH.write devNull) $ S.unfold readEx inh
439−
440−#ifdef INSPECTION
441−inspect $ hasNoTypeClasses 'readWriteBracket_Unfold
442−-- inspect $ 'readWriteBracketUnfold `hasNoType` ''Step
443−#endif
444−
445−{-# NOINLINE readWriteBracketUnfold #-}
446−readWriteBracketUnfold :: Handle -> Handle -> IO ()
447−readWriteBracketUnfold inh devNull =
448− let readEx = IUF.bracket return (\_ -> hClose inh) FH.read
449− in S.fold (FH.write devNull) $ S.unfold readEx inh
450−
451−o_1_space_copy_read_exceptions :: BenchEnv -> [Benchmark]
452−o_1_space_copy_read_exceptions env =
453− [ bgroup "copy/read/exceptions"
454− [ mkBenchSmall "UF.onException" env $ \inh _ ->
455− readWriteOnExceptionUnfold inh (nullH env)
456− , mkBenchSmall "UF.handle" env $ \inh _ ->
457− readWriteHandleExceptionUnfold inh (nullH env)
458− , mkBenchSmall "UF.finally_" env $ \inh _ ->
459− readWriteFinally_Unfold inh (nullH env)
460− , mkBenchSmall "UF.finally" env $ \inh _ ->
461− readWriteFinallyUnfold inh (nullH env)
462− , mkBenchSmall "UF.bracket_" env $ \inh _ ->
463− readWriteBracket_Unfold inh (nullH env)
464− , mkBenchSmall "UF.bracket" env $ \inh _ ->
465− readWriteBracketUnfold inh (nullH env)
466− ]
467− ]
468−
469−-------------------------------------------------------------------------------
470−-- stream exceptions
471−-------------------------------------------------------------------------------
472−
473−-- | Send the file contents to /dev/null with exception handling
474−{-# NOINLINE readWriteOnExceptionStream #-}
475−readWriteOnExceptionStream :: Handle -> Handle -> IO ()
476−readWriteOnExceptionStream inh devNull =
477− let readEx = S.onException (hClose inh) (S.unfold FH.read inh)
478− in S.fold (FH.write devNull) $ readEx
479−
480−-- | Send the file contents to /dev/null with exception handling
481−{-# NOINLINE readWriteHandleExceptionStream #-}
482−readWriteHandleExceptionStream :: Handle -> Handle -> IO ()
483−readWriteHandleExceptionStream inh devNull =
484− let handler (_e :: SomeException) = S.yieldM (hClose inh >> return 10)
485− readEx = S.handle handler (S.unfold FH.read inh)
486− in S.fold (FH.write devNull) $ readEx
487−
488−-- | Send the file contents to /dev/null with exception handling
489−{-# NOINLINE readWriteFinally_Stream #-}
490−readWriteFinally_Stream :: Handle -> Handle -> IO ()
491−readWriteFinally_Stream inh devNull =
492− let readEx = IP.finally_ (hClose inh) (S.unfold FH.read inh)
493− in S.fold (FH.write devNull) readEx
494−
495−{-# NOINLINE readWriteFinallyStream #-}
496−readWriteFinallyStream :: Handle -> Handle -> IO ()
497−readWriteFinallyStream inh devNull =
498− let readEx = S.finally (hClose inh) (S.unfold FH.read inh)
499− in S.fold (FH.write devNull) readEx
500−
501−-- | Send the file contents to /dev/null with exception handling
502−fromToBytesBracket_Stream :: Handle -> Handle -> IO ()
503−fromToBytesBracket_Stream inh devNull =
504− let readEx = IP.bracket_ (return ()) (\_ -> hClose inh)
505− (\_ -> IFH.toBytes inh)
506− in IFH.fromBytes devNull $ readEx
507−
508−#ifdef INSPECTION
509−inspect $ hasNoTypeClasses 'fromToBytesBracket_Stream
510−-- inspect $ 'fromToBytesBracketStream `hasNoType` ''Step
511−#endif
512−
513−fromToBytesBracketStream :: Handle -> Handle -> IO ()
514−fromToBytesBracketStream inh devNull =
515− let readEx = S.bracket (return ()) (\_ -> hClose inh)
516− (\_ -> IFH.toBytes inh)
517− in IFH.fromBytes devNull $ readEx
518−
519−{-# NOINLINE readWriteBeforeAfterStream #-}
520−readWriteBeforeAfterStream :: Handle -> Handle -> IO ()
521−readWriteBeforeAfterStream inh devNull =
522− let readEx =
523− IP.after (hClose inh)
524− $ IP.before (hPutChar devNull 'A') (S.unfold FH.read inh)
525− in S.fold (FH.write devNull) readEx
526−
527−{-# NOINLINE readWriteAfterStream #-}
528−readWriteAfterStream :: Handle -> Handle -> IO ()
529−readWriteAfterStream inh devNull =
530− let readEx = IP.after (hClose inh) (S.unfold FH.read inh)
531− in S.fold (FH.write devNull) readEx
532−
533−{-# NOINLINE readWriteAfter_Stream #-}
534−readWriteAfter_Stream :: Handle -> Handle -> IO ()
535−readWriteAfter_Stream inh devNull =
536− let readEx = IP.after_ (hClose inh) (S.unfold FH.read inh)
537− in S.fold (FH.write devNull) readEx
538−
539−o_1_space_copy_stream_exceptions :: BenchEnv -> [Benchmark]
540−o_1_space_copy_stream_exceptions env =
541− [ bgroup "copy/read/exceptions"
542− [ mkBenchSmall "S.onException" env $ \inh _ ->
543− readWriteOnExceptionStream inh (nullH env)
544− , mkBenchSmall "S.handle" env $ \inh _ ->
545− readWriteHandleExceptionStream inh (nullH env)
546− , mkBenchSmall "S.finally_" env $ \inh _ ->
547− readWriteFinally_Stream inh (nullH env)
548− , mkBenchSmall "S.finally" env $ \inh _ ->
549− readWriteFinallyStream inh (nullH env)
550− , mkBenchSmall "S.after . S.before" env $ \inh _ ->
551− readWriteBeforeAfterStream inh (nullH env)
552− , mkBenchSmall "S.after" env $ \inh _ ->
553− readWriteAfterStream inh (nullH env)
554− , mkBenchSmall "S.after_" env $ \inh _ ->
555− readWriteAfter_Stream inh (nullH env)
556− ]
557− , bgroup "copy/fromToBytes/exceptions"
558− [ mkBenchSmall "S.bracket_" env $ \inh _ ->
559− fromToBytesBracket_Stream inh (nullH env)
560− , mkBenchSmall "S.bracket" env $ \inh _ ->
561− fromToBytesBracketStream inh (nullH env)
562− ]
563− ]
564−
565306-------------------------------------------------------------------------------
566307-- copy with group/ungroup transformations
567308-------------------------------------------------------------------------------
@@ -725,13 +466,9 @@ o_1_space_copy_read_group_ungroup env =
725466allBenchmarks :: BenchEnv -> [Benchmark]
726467allBenchmarks env = Prelude.concat
727468 [ o_1_space_copy_chunked env
728− , o_1_space_copy_exceptions_readChunks env
729− , o_1_space_copy_exceptions_toChunks env
730469 , o_1_space_copy_read env
731470 , o_1_space_copy_fromBytes env
732471 , o_1_space_copy env
733− , o_1_space_copy_read_exceptions env
734− , o_1_space_copy_stream_exceptions env
735472 , o_1_space_copy_toChunks_group_ungroup env
736473 , o_1_space_copy_read_group_ungroup env
737474 ]