@@ -20,9 +20,12 @@
21module Serial.Exceptions (benchmarks) where
21module Serial.Exceptions (benchmarks) where
23−import Control.Exception (SomeException)
23+import Control.Exception (SomeException, Exception, throwIO)
24import System.IO (Handle, hClose, hPutChar)
24import System.IO (Handle, hClose, hPutChar)
26+import qualified Data.IORef as Ref
27+import qualified Data.Map.Strict as Map
26import qualified Streamly.FileSystem.Handle as FH
29import qualified Streamly.FileSystem.Handle as FH
27import qualified Streamly.Internal.Data.Unfold as IUF
30import qualified Streamly.Internal.Data.Unfold as IUF
28import qualified Streamly.Internal.FileSystem.Handle as IFH
31import qualified Streamly.Internal.FileSystem.Handle as IFH
@@ -44,6 +47,79 @@ import qualified Streamly.Internal.Data.Stream.StreamD as D
44-- stream exceptions
47-- stream exceptions
45-------------------------------------------------------------------------------
48-------------------------------------------------------------------------------
53+ deriving (Show, Eq, Ord)
55+instance Exception BenchException
57+retryNoneSimple :: Int -> Int -> IO ()
58+retryNoneSimple length from =
60+ $ IP.retry (Map.singleton BenchException1 length) (const S.nil) source
64+ source = S.enumerateFromTo from (from + length)
66+retryNone :: Int -> Int -> IO ()
67+retryNone length from = do
68+ ref <- Ref.newIORef (0 :: Int)
70+ $ IP.retry (Map.singleton BenchException1 length) (const S.nil)
76+ IP.replicateM (from + length)
77+ $ Ref.modifyIORef' ref (+ 1) >> Ref.readIORef ref
79+retryAll :: Int -> Int -> IO ()
80+retryAll length from = do
81+ ref <- Ref.newIORef 0
83+ $ IP.retry (Map.singleton BenchException1 (length + from)) (const S.nil)
91+ Ref.modifyIORef' ref (+ 1)
92+ val <- Ref.readIORef ref
95+ else throwIO BenchException1
97+retryUnknown :: Int -> Int -> IO ()
98+retryUnknown length from = do
100+ $ IP.retry (Map.singleton BenchException1 length) (const source)
101+ $ throwIO BenchException2 `S.before` S.nil
105+ source = S.enumerateFromTo from (from + length)
108+o_1_space_serial_exceptions :: Int -> [Benchmark]
109+o_1_space_serial_exceptions length =
112+ [ benchIOSrc1 "retryNoneSimple" (retryNoneSimple length)
113+ , benchIOSrc1 "retryNone" (retryNone length)
114+ , benchIOSrc1 "retryAll" (retryAll length)
115+ , benchIOSrc1 "retryUnknown" (retryUnknown length)
119+-------------------------------------------------------------------------------
120+-- copy stream exceptions
121+-------------------------------------------------------------------------------
47-- | Send the file contents to /dev/null with exception handling
123-- | Send the file contents to /dev/null with exception handling
48readWriteOnExceptionStream :: Handle -> Handle -> IO ()
124readWriteOnExceptionStream :: Handle -> Handle -> IO ()
49readWriteOnExceptionStream inh devNull =
125readWriteOnExceptionStream inh devNull =
@@ -230,11 +306,12 @@ o_1_space_copy_exceptions_toChunks env =
233−benchmarks :: String -> BenchEnv -> [Benchmark]
309+benchmarks :: String -> BenchEnv -> Int -> [Benchmark]
234−benchmarks moduleName env =
310+benchmarks moduleName env size =
235 [ bgroup (o_1_space_prefix moduleName) $ concat
311 [ bgroup (o_1_space_prefix moduleName) $ concat
236 [ o_1_space_copy_exceptions_readChunks env
312 [ o_1_space_copy_exceptions_readChunks env
237 , o_1_space_copy_exceptions_toChunks env
313 , o_1_space_copy_exceptions_toChunks env
238 , o_1_space_copy_stream_exceptions env
314 , o_1_space_copy_stream_exceptions env
315+ , o_1_space_serial_exceptions size