on master help sign in
Use smaller input files for longer benchmarks
53504dbHarendra Kumar
benchmark/Streamly/Benchmark/FileSystem/Handle.hs+280−294
@@ -19,12 +19,14 @@
19{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
19{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
20#endif
20#endif
21
21
22−import Control.DeepSeq (NFData)
22+import Control.DeepSeq (NFData(rnf))
23import Control.Exception (SomeException)
23import Control.Exception (SomeException)
24import Data.Char (ord, chr)
24import Data.Char (ord, chr)
25import Data.Functor.Identity (runIdentity)
25import Data.Functor.Identity (runIdentity)
26import Data.Word (Word8)
26import Data.Word (Word8)
27+#if __GLASGOW_HASKELL__ >= 800
27import System.Directory (getFileSize)
28import System.Directory (getFileSize)
29+#endif
28import System.Environment (lookupEnv)
30import System.Environment (lookupEnv)
29import System.IO (openFile, IOMode(..), Handle, hClose)
31import System.IO (openFile, IOMode(..), Handle, hClose)
30import System.Process.Typed (shell, runProcess_)
32import System.Process.Typed (shell, runProcess_)
@@ -92,25 +94,81 @@ blockSize = 32768
92blockCount :: Int -> Int
94blockCount :: Int -> Int
93blockCount size = (size + blockSize - 1) `div` blockSize
95blockCount size = (size + blockSize - 1) `div` blockSize
94
96
97+data RefHandles = RefHandles
98+ { smallInH :: Handle
99+ , bigInH :: Handle
100+ , outputH :: Handle
101+ }
102+
95−data Handles = Handles Handle Handle
103+data Handles = Handles !Handle !Handle
96−
104+
97−mkBench :: NFData b => String -> IORef Handles -> IO b -> Benchmark
105+instance NFData Handles where
98−mkBench name href action =
106+ rnf _ = ()
107+
108+data BenchEnv = BenchEnv
109+ { href :: IORef RefHandles
110+ , smallSize :: Int
111+ , bigSize :: Int
112+ , nullH :: Handle
113+ }
114+
115+withScaling :: BenchEnv -> String -> String
116+withScaling env str =
117+ let factor = round (fromIntegral (bigSize env)
118+ / (fromIntegral (smallSize env) :: Double)) :: Int
119+ in if factor == 1
120+ then str
121+ else str ++ " (1/" ++ show factor ++ ")"
122+
123+mkBenchCommon ::
124+ NFData b
125+ => (RefHandles -> Handles)
126+ -> String
127+ -> BenchEnv
128+ -> (Handle -> Handle -> IO b)
129+ -> Benchmark
130+mkBenchCommon mkHandles name env action =
99 bench name $ perRunEnv (do
131 bench name $ perRunEnv (do
100− Handles inH outH <- readIORef href
132+ r <- readIORef $ href env
101
133
102 -- close old handles
134 -- close old handles
103− hClose inH
135+ hClose $ smallInH r
104− hClose outH
136+ hClose $ bigInH r
137+ hClose $ outputH r
105
138
106 -- reopen
139 -- reopen
140+ smallInHandle <- openFile inFileSmall ReadMode
107− inh <- openFile inFileBig ReadMode
141+ bigInHandle <- openFile inFileBig ReadMode
108− outh <- openFile outfile WriteMode
142+ outHandle <- openFile outfile WriteMode
143+
144+ let refHandles = RefHandles
145+ { smallInH = smallInHandle
146+ , bigInH = bigInHandle
147+ , outputH = outHandle
148+ }
109
149
110 -- update
150 -- update
111− writeIORef href $ Handles inh outh
151+ writeIORef (href env) $ refHandles
152+ return $ mkHandles refHandles
112 )
153 )
113− (\_ -> action)
154+ (\(Handles h1 h2) -> action h1 h2)
155+
156+mkBench ::
157+ NFData b => String -> BenchEnv -> (Handle -> Handle -> IO b) -> Benchmark
158+mkBench name env action = mkBenchCommon useBigH name env action
159+
160+ where
161+
162+ useBigH (RefHandles {bigInH = inh, outputH = outh}) = Handles inh outh
163+
164+mkBenchSmall ::
165+ NFData b => String -> BenchEnv -> (Handle -> Handle -> IO b) -> Benchmark
166+mkBenchSmall name env action =
167+ mkBenchCommon useSmallH (withScaling env name) env action
168+
169+ where
170+
171+ useSmallH (RefHandles {smallInH = inh, outputH = outh}) = Handles inh outh
114
172
115-------------------------------------------------------------------------------
173-------------------------------------------------------------------------------
116-- read chunked using toChunks
174-- read chunked using toChunks
@@ -191,31 +249,25 @@ inspect $ hasNoTypeClasses 'decodeUtf8Lenient
191-- inspect $ 'decodeUtf8Lenient `hasNoType` ''D.ConcatMapUState
249-- inspect $ 'decodeUtf8Lenient `hasNoType` ''D.ConcatMapUState
192#endif
250#endif
193
251
194−o_1_space_read_chunked :: IORef Handles -> Handle -> Int -> [Benchmark]
252+o_1_space_read_chunked :: BenchEnv -> [Benchmark]
195−o_1_space_read_chunked href _ _ =
253+o_1_space_read_chunked env =
196 -- read using toChunks instead of read
254 -- read using toChunks instead of read
197 [ bgroup "reduce/toChunks"
255 [ bgroup "reduce/toChunks"
198− [ mkBench "S.last (32K)" href $ do
256+ [ mkBench "S.last (32K)" env $ \inH _ ->
199− Handles inh _ <- readIORef href
200− toChunksLast inh
257+ toChunksLast inH
201 -- Note: this cannot be fairly compared with GNU wc -c or wc -m as
258 -- Note: this cannot be fairly compared with GNU wc -c or wc -m as
202 -- wc uses lseek to just determine the file size rather than reading
259 -- wc uses lseek to just determine the file size rather than reading
203 -- and counting characters.
260 -- and counting characters.
204− , mkBench "S.sum . S.map A.length (32K)" href $ do
261+ , mkBench "S.sum . S.map A.length (32K)" env $ \inH _ ->
205− Handles inh _ <- readIORef href
206− toChunksSumLengths inh
262+ toChunksSumLengths inH
207− , mkBench "AS.splitOnSuffix (32K)" href $ do
263+ , mkBench "AS.splitOnSuffix (32K)" env $ \inH _ ->
208− Handles inh _ <- readIORef href
209− toChunksSplitOnSuffix inh
264+ toChunksSplitOnSuffix inH
210− , mkBench "AS.splitOn (32K)" href $ do
265+ , mkBench "AS.splitOn (32K)" env $ \inH _ ->
211− Handles inh _ <- readIORef href
212− toChunksSplitOn inh
266+ toChunksSplitOn inH
213− , mkBench "countBytes (32K)" href $ do
267+ , mkBench "countBytes (32K)" env $ \inH _ ->
214− Handles inh _ <- readIORef href
215− toChunksCountBytes inh
268+ toChunksCountBytes inH
216− , mkBench "US.decodeUtf8ArraysLenient (1MB)" href $ do
269+ , mkBenchSmall "US.decodeUtf8ArraysLenient (1MB)" env $ \inH _ ->
217− Handles inh _ <- readIORef href
218− toChunksWithBufferOfDecodeUtf8ArraysLenient inh
270+ toChunksWithBufferOfDecodeUtf8ArraysLenient inH
219 ]
271 ]
220 ]
272 ]
221
273
@@ -228,7 +280,7 @@ o_1_space_read_chunked href _ _ =
228-- | Send the file contents to /dev/null
280-- | Send the file contents to /dev/null
229{-# INLINE toChunksWithBufferOf #-}
281{-# INLINE toChunksWithBufferOf #-}
230toChunksWithBufferOf :: Handle -> Handle -> IO ()
282toChunksWithBufferOf :: Handle -> Handle -> IO ()
231−toChunksWithBufferOf devNull inh =
283+toChunksWithBufferOf inh devNull =
232 S.fold (IFH.writeChunks devNull) $ IFH.toChunksWithBufferOf (256*1024) inh
284 S.fold (IFH.writeChunks devNull) $ IFH.toChunksWithBufferOf (256*1024) inh
233
285
234#ifdef INSPECTION
286#ifdef INSPECTION
@@ -264,18 +316,15 @@ inspect $ hasNoTypeClasses 'copyCodecUtf8ArraysLenient
264-- inspect $ 'copyCodecUtf8ArraysLenient `hasNoType` ''D.ConcatMapUState
316-- inspect $ 'copyCodecUtf8ArraysLenient `hasNoType` ''D.ConcatMapUState
265#endif
317#endif
266
318
267−o_1_space_copy_chunked :: IORef Handles -> Handle -> Int -> [Benchmark]
319+o_1_space_copy_chunked :: BenchEnv -> [Benchmark]
268−o_1_space_copy_chunked href devNull _ =
320+o_1_space_copy_chunked env =
269 [ bgroup "copy/toChunks"
321 [ bgroup "copy/toChunks"
270− [ mkBench "toNull (256K)" href $ do
322+ [ mkBench "toNull (256K)" env $ \inH _ ->
271− Handles inh _ <- readIORef href
272− toChunksWithBufferOf devNull inh
323+ toChunksWithBufferOf inH (nullH env)
273− , mkBench "raw" href $ do
324+ , mkBench "raw" env $ \inH outH ->
274− Handles inh outh <- readIORef href
275− copyChunks inh outh
325+ copyChunks inH outH
276− , mkBench "decodeEncodeUtf8Lenient" href $ do
326+ , mkBenchSmall "decodeEncodeUtf8Lenient" env $ \inH outH ->
277− Handles inh outh <- readIORef href
278− copyCodecUtf8ArraysLenient inh outh
327+ copyCodecUtf8ArraysLenient inH outH
279 ]
328 ]
280 ]
329 ]
281
330
@@ -288,7 +337,7 @@ o_1_space_copy_chunked href devNull _ =
288-- | Send the file contents to /dev/null with exception handling
337-- | Send the file contents to /dev/null with exception handling
289{-# INLINE readChunksWithBufferOfOnExceptionUnfold #-}
338{-# INLINE readChunksWithBufferOfOnExceptionUnfold #-}
290readChunksWithBufferOfOnExceptionUnfold :: Handle -> Handle -> IO ()
339readChunksWithBufferOfOnExceptionUnfold :: Handle -> Handle -> IO ()
291−readChunksWithBufferOfOnExceptionUnfold devNull inh =
340+readChunksWithBufferOfOnExceptionUnfold inh devNull =
292 let readEx = IUF.onException (\_ -> hClose inh)
341 let readEx = IUF.onException (\_ -> hClose inh)
293 (IUF.supplyFirst FH.readChunksWithBufferOf (256*1024))
342 (IUF.supplyFirst FH.readChunksWithBufferOf (256*1024))
294 in IUF.fold readEx (IFH.writeChunks devNull) inh
343 in IUF.fold readEx (IFH.writeChunks devNull) inh
@@ -301,7 +350,7 @@ inspect $ hasNoTypeClasses 'readChunksWithBufferOfOnExceptionUnfold
301-- | Send the file contents to /dev/null with exception handling
350-- | Send the file contents to /dev/null with exception handling
302{-# INLINE readChunksWithBufferOfBracketUnfold #-}
351{-# INLINE readChunksWithBufferOfBracketUnfold #-}
303readChunksWithBufferOfBracketUnfold :: Handle -> Handle -> IO ()
352readChunksWithBufferOfBracketUnfold :: Handle -> Handle -> IO ()
304−readChunksWithBufferOfBracketUnfold devNull inh =
353+readChunksWithBufferOfBracketUnfold inh devNull =
305 let readEx = IUF.bracket return (\_ -> hClose inh)
354 let readEx = IUF.bracket return (\_ -> hClose inh)
306 (IUF.supplyFirst FH.readChunksWithBufferOf (256*1024))
355 (IUF.supplyFirst FH.readChunksWithBufferOf (256*1024))
307 in IUF.fold readEx (IFH.writeChunks devNull) inh
356 in IUF.fold readEx (IFH.writeChunks devNull) inh
@@ -313,23 +362,20 @@ inspect $ hasNoTypeClasses 'readChunksWithBufferOfBracketUnfold
313
362
314{-# INLINE readChunksWithBufferOfBracketIOUnfold #-}
363{-# INLINE readChunksWithBufferOfBracketIOUnfold #-}
315readChunksWithBufferOfBracketIOUnfold :: Handle -> Handle -> IO ()
364readChunksWithBufferOfBracketIOUnfold :: Handle -> Handle -> IO ()
316−readChunksWithBufferOfBracketIOUnfold devNull inh =
365+readChunksWithBufferOfBracketIOUnfold inh devNull =
317 let readEx = IUF.bracketIO return (\_ -> hClose inh)
366 let readEx = IUF.bracketIO return (\_ -> hClose inh)
318 (IUF.supplyFirst FH.readChunksWithBufferOf (256*1024))
367 (IUF.supplyFirst FH.readChunksWithBufferOf (256*1024))
319 in IUF.fold readEx (IFH.writeChunks devNull) inh
368 in IUF.fold readEx (IFH.writeChunks devNull) inh
320
369
321−o_1_space_copy_exceptions_readChunks :: IORef Handles -> Handle -> Int -> [Benchmark]
370+o_1_space_copy_exceptions_readChunks :: BenchEnv -> [Benchmark]
322−o_1_space_copy_exceptions_readChunks href devNull _ =
371+o_1_space_copy_exceptions_readChunks env =
323 [ bgroup "copy/exceptions/unfold/readChunks"
372 [ bgroup "copy/exceptions/unfold/readChunks"
324− [ mkBench "onException (256K)" href $ do
373+ [ mkBench "onException (256K)" env $ \inH _ ->
325− Handles inh _ <- readIORef href
326− readChunksWithBufferOfOnExceptionUnfold devNull inh
374+ readChunksWithBufferOfOnExceptionUnfold inH (nullH env)
327− , mkBench "bracket (256K)" href $ do
375+ , mkBench "bracket (256K)" env $ \inH _ ->
328− Handles inh _ <- readIORef href
329− readChunksWithBufferOfBracketUnfold devNull inh
376+ readChunksWithBufferOfBracketUnfold inH (nullH env)
330− , mkBench "bracketIO (256K)" href $ do
377+ , mkBench "bracketIO (256K)" env $ \inH _ ->
331− Handles inh _ <- readIORef href
332− readChunksWithBufferOfBracketIOUnfold devNull inh
378+ readChunksWithBufferOfBracketIOUnfold inH (nullH env)
333 ]
379 ]
334 ]
380 ]
335
381
@@ -340,7 +386,7 @@ o_1_space_copy_exceptions_readChunks href devNull _ =
340-- | Send the file contents to /dev/null with exception handling
386-- | Send the file contents to /dev/null with exception handling
341{-# INLINE toChunksWithBufferOfBracketStream #-}
387{-# INLINE toChunksWithBufferOfBracketStream #-}
342toChunksWithBufferOfBracketStream :: Handle -> Handle -> IO ()
388toChunksWithBufferOfBracketStream :: Handle -> Handle -> IO ()
343−toChunksWithBufferOfBracketStream devNull inh =
389+toChunksWithBufferOfBracketStream inh devNull =
344 let readEx = S.bracket (return ()) (\_ -> hClose inh)
390 let readEx = S.bracket (return ()) (\_ -> hClose inh)
345 (\_ -> IFH.toChunksWithBufferOf (256*1024) inh)
391 (\_ -> IFH.toChunksWithBufferOf (256*1024) inh)
346 in S.fold (IFH.writeChunks devNull) $ readEx
392 in S.fold (IFH.writeChunks devNull) $ readEx
@@ -352,20 +398,18 @@ inspect $ hasNoTypeClasses 'toChunksWithBufferOfBracketStream
352
398
353{-# INLINE toChunksWithBufferOfBracketIOStream #-}
399{-# INLINE toChunksWithBufferOfBracketIOStream #-}
354toChunksWithBufferOfBracketIOStream :: Handle -> Handle -> IO ()
400toChunksWithBufferOfBracketIOStream :: Handle -> Handle -> IO ()
355−toChunksWithBufferOfBracketIOStream devNull inh =
401+toChunksWithBufferOfBracketIOStream inh devNull =
356 let readEx = IP.bracketIO (return ()) (\_ -> hClose inh)
402 let readEx = IP.bracketIO (return ()) (\_ -> hClose inh)
357 (\_ -> IFH.toChunksWithBufferOf (256*1024) inh)
403 (\_ -> IFH.toChunksWithBufferOf (256*1024) inh)
358 in S.fold (IFH.writeChunks devNull) $ readEx
404 in S.fold (IFH.writeChunks devNull) $ readEx
359
405
360−o_1_space_copy_exceptions_toChunks :: IORef Handles -> Handle -> Int -> [Benchmark]
406+o_1_space_copy_exceptions_toChunks :: BenchEnv -> [Benchmark]
361−o_1_space_copy_exceptions_toChunks href devNull _ =
407+o_1_space_copy_exceptions_toChunks env =
362 [ bgroup "copy/exceptions/stream/toChunks"
408 [ bgroup "copy/exceptions/stream/toChunks"
363− [ mkBench "bracket (256K)" href $ do
409+ [ mkBench "bracket (256K)" env $ \inH _ ->
364− Handles inh _ <- readIORef href
365− toChunksWithBufferOfBracketStream devNull inh
410+ toChunksWithBufferOfBracketStream inH (nullH env)
366− , mkBench "bracketIO (256K)" href $ do
411+ , mkBench "bracketIO (256K)" env $ \inH _ ->
367− Handles inh _ <- readIORef href
368− toChunksWithBufferOfBracketIOStream devNull inh
412+ toChunksWithBufferOfBracketIOStream inH (nullH env)
369 ]
413 ]
370 ]
414 ]
371
415
@@ -466,37 +510,29 @@ inspect $ hasNoTypeClasses 'readDecodeUtf8Lax
466-- inspect $ 'readDecodeUtf8Lax `hasNoType` ''D.ConcatMapUState
510-- inspect $ 'readDecodeUtf8Lax `hasNoType` ''D.ConcatMapUState
467#endif
511#endif
468
512
469−o_1_space_reduce_read :: IORef Handles -> Handle -> Int -> [Benchmark]
513+o_1_space_reduce_read :: BenchEnv -> [Benchmark]
470−o_1_space_reduce_read href _ _ =
514+o_1_space_reduce_read env =
471 [ bgroup "reduce/read"
515 [ bgroup "reduce/read"
472 [ -- read raw bytes without any decoding
516 [ -- read raw bytes without any decoding
473− mkBench "S.drain" href $ do
517+ mkBench "S.drain" env $ \inh _ ->
474− Handles inh _ <- readIORef href
475 readDrain inh
518 readDrain inh
476− , mkBench "S.last" href $ do
519+ , mkBench "S.last" env $ \inh _ ->
477− Handles inh _ <- readIORef href
478 readLast inh
520 readLast inh
479− , mkBench "S.sum" href $ do
521+ , mkBench "S.sum" env $ \inh _ ->
480− Handles inh _ <- readIORef href
481 readSumBytes inh
522 readSumBytes inh
482
523
483 -- read with Latin1 decoding
524 -- read with Latin1 decoding
484− , mkBench "SS.decodeLatin1" href $ do
525+ , mkBench "SS.decodeLatin1" env $ \inh _ ->
485− Handles inh _ <- readIORef href
486 readDecodeLatin1 inh
526 readDecodeLatin1 inh
487− , mkBench "S.length" href $ do
527+ , mkBench "S.length" env $ \inh _ ->
488− Handles inh _ <- readIORef href
489 readCountBytes inh
528 readCountBytes inh
490− , mkBench "US.lines . SS.decodeLatin1" href $ do
529+ , mkBench "US.lines . SS.decodeLatin1" env $ \inh _ ->
491− Handles inh _ <- readIORef href
492 readCountLines inh
530 readCountLines inh
493− , mkBench "US.words . SS.decodeLatin1" href $ do
531+ , mkBenchSmall "US.words . SS.decodeLatin1" env $ \inh _ ->
494− Handles inh _ <- readIORef href
495 readCountWords inh
532 readCountWords inh
496
533
497 -- read with utf8 decoding
534 -- read with utf8 decoding
498− , mkBench "SS.decodeUtf8Lax" href $ do
535+ , mkBenchSmall "SS.decodeUtf8Lax" env $ \inh _ ->
499− Handles inh _ <- readIORef href
500 readDecodeUtf8Lax inh
536 readDecodeUtf8Lax inh
501 ]
537 ]
502 ]
538 ]
@@ -521,11 +557,10 @@ inspect $ 'countLinesU `hasNoType` ''Step
521inspect $ 'countLinesU `hasNoType` ''D.ConcatMapUState
557inspect $ 'countLinesU `hasNoType` ''D.ConcatMapUState
522#endif
558#endif
523
559
524−o_1_space_reduce_toBytes :: IORef Handles -> Handle -> Int -> [Benchmark]
560+o_1_space_reduce_toBytes :: BenchEnv -> [Benchmark]
525−o_1_space_reduce_toBytes href _ _ =
561+o_1_space_reduce_toBytes env =
526 [ bgroup "reduce/toBytes"
562 [ bgroup "reduce/toBytes"
527− [ mkBench "US.lines . SS.decodeLatin1" href $ do
563+ [ mkBench "US.lines . SS.decodeLatin1" env $ \inh _ ->
528− Handles inh _ <- readIORef href
529 toChunksConcatUnfoldCountLines inh
564 toChunksConcatUnfoldCountLines inh
530 ]
565 ]
531 ]
566 ]
@@ -578,34 +613,28 @@ inspect $ '_chunksOfD `hasNoType` ''AT.FlattenState
578inspect $ '_chunksOfD `hasNoType` ''D.ConcatMapUState
613inspect $ '_chunksOfD `hasNoType` ''D.ConcatMapUState
579#endif
614#endif
580
615
581−o_1_space_reduce_read_grouped :: IORef Handles -> Handle -> Int -> [Benchmark]
616+o_1_space_reduce_read_grouped :: BenchEnv -> [Benchmark]
582−o_1_space_reduce_read_grouped href _ value =
617+o_1_space_reduce_read_grouped env =
583 [ bgroup "reduce/read/chunks"
618 [ bgroup "reduce/read/chunks"
584− [ mkBench ("S.chunksOf " ++ show value ++ " FL.sum") href $ do
619+ [ mkBench ("S.chunksOf " ++ show (bigSize env) ++ " FL.sum") env $
585− Handles inh _ <- readIORef href
620+ \inh _ ->
586− chunksOfSum value inh
621+ chunksOfSum (bigSize env) inh
587− , mkBench "S.chunksOf 1 FL.sum" href $ do
622+ , mkBench "S.chunksOf 1 FL.sum" env $ \inh _ ->
588− Handles inh _ <- readIORef href
589 chunksOfSum 1 inh
623 chunksOfSum 1 inh
590
624
591 -- Chunk using parsers
625 -- Chunk using parsers
592− , mkBench ("S.parseMany (PR.take " ++ show value ++ " FL.sum)")
626+ , mkBenchSmall ("S.parseMany (PR.take " ++ show (bigSize env) ++ " FL.sum)")
593− href $ do
627+ env $ \inh _ ->
594− Handles inh _ <- readIORef href
595− parseManyChunksOfSum value inh
628+ parseManyChunksOfSum (bigSize env) inh
596− , mkBench "S.parseMany (PR.take 1 FL.sum)" href $ do
629+ , mkBench "S.parseMany (PR.take 1 FL.sum)" env $ \inh _ ->
597− Handles inh _ <- readIORef href
598 parseManyChunksOfSum 1 inh
630 parseManyChunksOfSum 1 inh
599
631
600 -- folding chunks to arrays
632 -- folding chunks to arrays
601− , mkBench "S.arraysOf 1" href $ do
633+ , mkBenchSmall "S.arraysOf 1" env $ \inh _ ->
602− Handles inh _ <- readIORef href
603 chunksOf 1 inh
634 chunksOf 1 inh
604− , mkBench "S.arraysOf 10" href $ do
635+ , mkBench "S.arraysOf 10" env $ \inh _ ->
605− Handles inh _ <- readIORef href
606 chunksOf 10 inh
636 chunksOf 10 inh
607− , mkBench "S.arraysOf 1000" href $ do
637+ , mkBench "S.arraysOf 1000" env $ \inh _ ->
608− Handles inh _ <- readIORef href
609 chunksOf 1000 inh
638 chunksOf 1000 inh
610 ]
639 ]
611 ]
640 ]
@@ -617,7 +646,7 @@ o_1_space_reduce_read_grouped href _ value =
617-- | Send the file contents to /dev/null
646-- | Send the file contents to /dev/null
618{-# INLINE readWriteNull #-}
647{-# INLINE readWriteNull #-}
619readWriteNull :: Handle -> Handle -> IO ()
648readWriteNull :: Handle -> Handle -> IO ()
620−readWriteNull devNull inh = S.fold (FH.write devNull) $ S.unfold FH.read inh
649+readWriteNull inh devNull = S.fold (FH.write devNull) $ S.unfold FH.read inh
621
650
622#ifdef INSPECTION
651#ifdef INSPECTION
623inspect $ hasNoTypeClasses 'readWriteNull
652inspect $ hasNoTypeClasses 'readWriteNull
@@ -686,26 +715,21 @@ inspect $ hasNoTypeClasses 'copyStreamUtf8Lax
686-- inspect $ 'copyStreamUtf8Lax `hasNoType` ''D.ConcatMapUState
715-- inspect $ 'copyStreamUtf8Lax `hasNoType` ''D.ConcatMapUState
687#endif
716#endif
688
717
689−o_1_space_copy_read :: IORef Handles -> Handle -> Int -> [Benchmark]
718+o_1_space_copy_read :: BenchEnv -> [Benchmark]
690−o_1_space_copy_read href devNull _ =
719+o_1_space_copy_read env =
691 [ bgroup "copy/read"
720 [ bgroup "copy/read"
692− [ mkBench "rawToNull" href $ do
721+ [ mkBench "rawToNull" env $ \inh _ ->
693− Handles inh _ <- readIORef href
694− readWriteNull devNull inh
722+ readWriteNull inh (nullH env)
695− , mkBench "rawToFile" href $ do
723+ , mkBench "rawToFile" env $ \inh outh ->
696− Handles inh outh <- readIORef href
697 copyStream inh outh
724 copyStream inh outh
698 -- This needs an ascii file, as decode just errors out.
725 -- This needs an ascii file, as decode just errors out.
699− , mkBench "SS.encodeLatin1 . SS.decodeLatin1" href $ do
726+ , mkBench "SS.encodeLatin1 . SS.decodeLatin1" env $ \inh outh ->
700− Handles inh outh <- readIORef href
701 copyStreamLatin1 inh outh
727 copyStreamLatin1 inh outh
702#ifdef DEVBUILD
728#ifdef DEVBUILD
703− , mkBench "copyUtf8" href $ do
729+ , mkBench "copyUtf8" env $ \inh outh ->
704− Handles inh outh <- readIORef href
705 _copyStreamUtf8 inh outh
730 _copyStreamUtf8 inh outh
706#endif
731#endif
707− , mkBench "SS.encodeUtf8 . SS.decodeUtf8Lax" href $ do
732+ , mkBenchSmall "SS.encodeUtf8 . SS.decodeUtf8Lax" env $ \inh outh ->
708− Handles inh outh <- readIORef href
709 copyStreamUtf8Lax inh outh
733 copyStreamUtf8Lax inh outh
710 ]
734 ]
711 ]
735 ]
@@ -717,7 +741,7 @@ o_1_space_copy_read href devNull _ =
717-- | Send the file contents to /dev/null
741-- | Send the file contents to /dev/null
718{-# INLINE readFromBytesNull #-}
742{-# INLINE readFromBytesNull #-}
719readFromBytesNull :: Handle -> Handle -> IO ()
743readFromBytesNull :: Handle -> Handle -> IO ()
720−readFromBytesNull devNull inh = IFH.fromBytes devNull $ S.unfold FH.read inh
744+readFromBytesNull inh devNull = IFH.fromBytes devNull $ S.unfold FH.read inh
721
745
722#ifdef INSPECTION
746#ifdef INSPECTION
723inspect $ hasNoTypeClasses 'catStreamWrite
747inspect $ hasNoTypeClasses 'catStreamWrite
@@ -726,12 +750,11 @@ inspect $ 'catStreamWrite `hasNoType` ''AT.FlattenState
726inspect $ 'catStreamWrite `hasNoType` ''D.ConcatMapUState
750inspect $ 'catStreamWrite `hasNoType` ''D.ConcatMapUState
727#endif
751#endif
728
752
729−o_1_space_copy_fromBytes :: IORef Handles -> Handle -> Int -> [Benchmark]
753+o_1_space_copy_fromBytes :: BenchEnv -> [Benchmark]
730−o_1_space_copy_fromBytes href devNull _ =
754+o_1_space_copy_fromBytes env =
731 [ bgroup "copy/fromBytes"
755 [ bgroup "copy/fromBytes"
732− [ mkBench "rawToNull" href $ do
756+ [ mkBench "rawToNull" env $ \inh _ ->
733− Handles inh _ <- readIORef href
734− readFromBytesNull devNull inh
757+ readFromBytesNull inh (nullH env)
735 ]
758 ]
736 ]
759 ]
737
760
@@ -742,7 +765,7 @@ o_1_space_copy_fromBytes href devNull _ =
742-- | Send the file contents to /dev/null with exception handling
765-- | Send the file contents to /dev/null with exception handling
743{-# INLINE readWriteOnExceptionUnfold #-}
766{-# INLINE readWriteOnExceptionUnfold #-}
744readWriteOnExceptionUnfold :: Handle -> Handle -> IO ()
767readWriteOnExceptionUnfold :: Handle -> Handle -> IO ()
745−readWriteOnExceptionUnfold devNull inh =
768+readWriteOnExceptionUnfold inh devNull =
746 let readEx = IUF.onException (\_ -> hClose inh) FH.read
769 let readEx = IUF.onException (\_ -> hClose inh) FH.read
747 in S.fold (FH.write devNull) $ S.unfold readEx inh
770 in S.fold (FH.write devNull) $ S.unfold readEx inh
748
771
@@ -756,7 +779,7 @@ inspect $ hasNoTypeClasses 'readWriteOnExceptionUnfold
756-- | Send the file contents to /dev/null with exception handling
779-- | Send the file contents to /dev/null with exception handling
757{-# INLINE readWriteHandleExceptionUnfold #-}
780{-# INLINE readWriteHandleExceptionUnfold #-}
758readWriteHandleExceptionUnfold :: Handle -> Handle -> IO ()
781readWriteHandleExceptionUnfold :: Handle -> Handle -> IO ()
759−readWriteHandleExceptionUnfold devNull inh =
782+readWriteHandleExceptionUnfold inh devNull =
760 let handler (_e :: SomeException) = hClose inh >> return 10
783 let handler (_e :: SomeException) = hClose inh >> return 10
761 readEx = IUF.handle (IUF.singletonM handler) FH.read
784 readEx = IUF.handle (IUF.singletonM handler) FH.read
762 in S.fold (FH.write devNull) $ S.unfold readEx inh
785 in S.fold (FH.write devNull) $ S.unfold readEx inh
@@ -771,7 +794,7 @@ inspect $ hasNoTypeClasses 'readWriteHandleExceptionUnfold
771-- | Send the file contents to /dev/null with exception handling
794-- | Send the file contents to /dev/null with exception handling
772{-# INLINE readWriteFinallyUnfold #-}
795{-# INLINE readWriteFinallyUnfold #-}
773readWriteFinallyUnfold :: Handle -> Handle -> IO ()
796readWriteFinallyUnfold :: Handle -> Handle -> IO ()
774−readWriteFinallyUnfold devNull inh =
797+readWriteFinallyUnfold inh devNull =
775 let readEx = IUF.finally (\_ -> hClose inh) FH.read
798 let readEx = IUF.finally (\_ -> hClose inh) FH.read
776 in S.fold (FH.write devNull) $ S.unfold readEx inh
799 in S.fold (FH.write devNull) $ S.unfold readEx inh
777
800
@@ -784,14 +807,14 @@ inspect $ hasNoTypeClasses 'readWriteFinallyUnfold
784
807
785{-# INLINE readWriteFinallyIOUnfold #-}
808{-# INLINE readWriteFinallyIOUnfold #-}
786readWriteFinallyIOUnfold :: Handle -> Handle -> IO ()
809readWriteFinallyIOUnfold :: Handle -> Handle -> IO ()
787−readWriteFinallyIOUnfold devNull inh =
810+readWriteFinallyIOUnfold inh devNull =
788 let readEx = IUF.finallyIO (\_ -> hClose inh) FH.read
811 let readEx = IUF.finallyIO (\_ -> hClose inh) FH.read
789 in S.fold (FH.write devNull) $ S.unfold readEx inh
812 in S.fold (FH.write devNull) $ S.unfold readEx inh
790
813
791-- | Send the file contents to /dev/null with exception handling
814-- | Send the file contents to /dev/null with exception handling
792{-# INLINE readWriteBracketUnfold #-}
815{-# INLINE readWriteBracketUnfold #-}
793readWriteBracketUnfold :: Handle -> Handle -> IO ()
816readWriteBracketUnfold :: Handle -> Handle -> IO ()
794−readWriteBracketUnfold devNull inh =
817+readWriteBracketUnfold inh devNull =
795 let readEx = IUF.bracket return (\_ -> hClose inh) FH.read
818 let readEx = IUF.bracket return (\_ -> hClose inh) FH.read
796 in S.fold (FH.write devNull) $ S.unfold readEx inh
819 in S.fold (FH.write devNull) $ S.unfold readEx inh
797
820
@@ -804,32 +827,25 @@ inspect $ hasNoTypeClasses 'readWriteBracketUnfold
804
827
805{-# INLINE readWriteBracketIOUnfold #-}
828{-# INLINE readWriteBracketIOUnfold #-}
806readWriteBracketIOUnfold :: Handle -> Handle -> IO ()
829readWriteBracketIOUnfold :: Handle -> Handle -> IO ()
807−readWriteBracketIOUnfold devNull inh =
830+readWriteBracketIOUnfold inh devNull =
808 let readEx = IUF.bracketIO return (\_ -> hClose inh) FH.read
831 let readEx = IUF.bracketIO return (\_ -> hClose inh) FH.read
809 in S.fold (FH.write devNull) $ S.unfold readEx inh
832 in S.fold (FH.write devNull) $ S.unfold readEx inh
810
833
811−o_1_space_copy_read_exceptions ::
834+o_1_space_copy_read_exceptions :: BenchEnv -> [Benchmark]
812− IORef Handles -> Handle -> Int -> [Benchmark]
813−o_1_space_copy_read_exceptions href devNull _ =
835+o_1_space_copy_read_exceptions env =
814 [ bgroup "copy/read/exceptions"
836 [ bgroup "copy/read/exceptions"
815− [ mkBench "UF.onException" href $ do
837+ [ mkBenchSmall "UF.onException" env $ \inh _ ->
816− Handles inh _ <- readIORef href
817− readWriteOnExceptionUnfold devNull inh
838+ readWriteOnExceptionUnfold inh (nullH env)
818− , mkBench "UF.handle" href $ do
839+ , mkBenchSmall "UF.handle" env $ \inh _ ->
819− Handles inh _ <- readIORef href
820− readWriteHandleExceptionUnfold devNull inh
840+ readWriteHandleExceptionUnfold inh (nullH env)
821− , mkBench "UF.finally" href $ do
841+ , mkBenchSmall "UF.finally" env $ \inh _ ->
822− Handles inh _ <- readIORef href
823− readWriteFinallyUnfold devNull inh
842+ readWriteFinallyUnfold inh (nullH env)
824− , mkBench "UF.finallyIO" href $ do
843+ , mkBenchSmall "UF.finallyIO" env $ \inh _ ->
825− Handles inh _ <- readIORef href
826− readWriteFinallyIOUnfold devNull inh
844+ readWriteFinallyIOUnfold inh (nullH env)
827− , mkBench "UF.bracket" href $ do
845+ , mkBenchSmall "UF.bracket" env $ \inh _ ->
828− Handles inh _ <- readIORef href
829− readWriteBracketUnfold devNull inh
846+ readWriteBracketUnfold inh (nullH env)
830− , mkBench "UF.bracketIO" href $ do
847+ , mkBenchSmall "UF.bracketIO" env $ \inh _ ->
831− Handles inh _ <- readIORef href
832− readWriteBracketIOUnfold devNull inh
848+ readWriteBracketIOUnfold inh (nullH env)
833 ]
849 ]
834 ]
850 ]
835
851
@@ -840,14 +856,14 @@ o_1_space_copy_read_exceptions href devNull _ =
840-- | Send the file contents to /dev/null with exception handling
856-- | Send the file contents to /dev/null with exception handling
841{-# INLINE readWriteOnExceptionStream #-}
857{-# INLINE readWriteOnExceptionStream #-}
842readWriteOnExceptionStream :: Handle -> Handle -> IO ()
858readWriteOnExceptionStream :: Handle -> Handle -> IO ()
843−readWriteOnExceptionStream devNull inh =
859+readWriteOnExceptionStream inh devNull =
844 let readEx = S.onException (hClose inh) (S.unfold FH.read inh)
860 let readEx = S.onException (hClose inh) (S.unfold FH.read inh)
845 in S.fold (FH.write devNull) $ readEx
861 in S.fold (FH.write devNull) $ readEx
846
862
847-- | Send the file contents to /dev/null with exception handling
863-- | Send the file contents to /dev/null with exception handling
848{-# INLINE readWriteHandleExceptionStream #-}
864{-# INLINE readWriteHandleExceptionStream #-}
849readWriteHandleExceptionStream :: Handle -> Handle -> IO ()
865readWriteHandleExceptionStream :: Handle -> Handle -> IO ()
850−readWriteHandleExceptionStream devNull inh =
866+readWriteHandleExceptionStream inh devNull =
851 let handler (_e :: SomeException) = S.yieldM (hClose inh >> return 10)
867 let handler (_e :: SomeException) = S.yieldM (hClose inh >> return 10)
852 readEx = S.handle handler (S.unfold FH.read inh)
868 readEx = S.handle handler (S.unfold FH.read inh)
853 in S.fold (FH.write devNull) $ readEx
869 in S.fold (FH.write devNull) $ readEx
@@ -855,20 +871,20 @@ readWriteHandleExceptionStream devNull inh =
855-- | Send the file contents to /dev/null with exception handling
871-- | Send the file contents to /dev/null with exception handling
856{-# INLINE readWriteFinallyStream #-}
872{-# INLINE readWriteFinallyStream #-}
857readWriteFinallyStream :: Handle -> Handle -> IO ()
873readWriteFinallyStream :: Handle -> Handle -> IO ()
858−readWriteFinallyStream devNull inh =
874+readWriteFinallyStream inh devNull =
859 let readEx = S.finally (hClose inh) (S.unfold FH.read inh)
875 let readEx = S.finally (hClose inh) (S.unfold FH.read inh)
860 in S.fold (FH.write devNull) readEx
876 in S.fold (FH.write devNull) readEx
861
877
862{-# INLINE readWriteFinallyIOStream #-}
878{-# INLINE readWriteFinallyIOStream #-}
863readWriteFinallyIOStream :: Handle -> Handle -> IO ()
879readWriteFinallyIOStream :: Handle -> Handle -> IO ()
864−readWriteFinallyIOStream devNull inh =
880+readWriteFinallyIOStream inh devNull =
865 let readEx = IP.finallyIO (hClose inh) (S.unfold FH.read inh)
881 let readEx = IP.finallyIO (hClose inh) (S.unfold FH.read inh)
866 in S.fold (FH.write devNull) readEx
882 in S.fold (FH.write devNull) readEx
867
883
868-- | Send the file contents to /dev/null with exception handling
884-- | Send the file contents to /dev/null with exception handling
869{-# INLINE fromToBytesBracketStream #-}
885{-# INLINE fromToBytesBracketStream #-}
870fromToBytesBracketStream :: Handle -> Handle -> IO ()
886fromToBytesBracketStream :: Handle -> Handle -> IO ()
871−fromToBytesBracketStream devNull inh =
887+fromToBytesBracketStream inh devNull =
872 let readEx = S.bracket (return ()) (\_ -> hClose inh)
888 let readEx = S.bracket (return ()) (\_ -> hClose inh)
873 (\_ -> IFH.toBytes inh)
889 (\_ -> IFH.toBytes inh)
874 in IFH.fromBytes devNull $ readEx
890 in IFH.fromBytes devNull $ readEx
@@ -880,35 +896,28 @@ inspect $ hasNoTypeClasses 'readWriteBracketStream
880
896
881{-# INLINE fromToBytesBracketIOStream #-}
897{-# INLINE fromToBytesBracketIOStream #-}
882fromToBytesBracketIOStream :: Handle -> Handle -> IO ()
898fromToBytesBracketIOStream :: Handle -> Handle -> IO ()
883−fromToBytesBracketIOStream devNull inh =
899+fromToBytesBracketIOStream inh devNull =
884 let readEx = IP.bracketIO (return ()) (\_ -> hClose inh)
900 let readEx = IP.bracketIO (return ()) (\_ -> hClose inh)
885 (\_ -> IFH.toBytes inh)
901 (\_ -> IFH.toBytes inh)
886 in IFH.fromBytes devNull $ readEx
902 in IFH.fromBytes devNull $ readEx
887
903
888−o_1_space_copy_stream_exceptions ::
904+o_1_space_copy_stream_exceptions :: BenchEnv -> [Benchmark]
889− IORef Handles -> Handle -> Int -> [Benchmark]
890−o_1_space_copy_stream_exceptions href devNull _ =
905+o_1_space_copy_stream_exceptions env =
891 [ bgroup "copy/read/exceptions"
906 [ bgroup "copy/read/exceptions"
892− [ mkBench "S.onException" href $ do
907+ [ mkBenchSmall "S.onException" env $ \inh _ ->
893− Handles inh _ <- readIORef href
894− readWriteOnExceptionStream devNull inh
908+ readWriteOnExceptionStream inh (nullH env)
895− , mkBench "S.handle" href $ do
909+ , mkBenchSmall "S.handle" env $ \inh _ ->
896− Handles inh _ <- readIORef href
897− readWriteHandleExceptionStream devNull inh
910+ readWriteHandleExceptionStream inh (nullH env)
898− , mkBench "S.finally" href $ do
911+ , mkBenchSmall "S.finally" env $ \inh _ ->
899− Handles inh _ <- readIORef href
900− readWriteFinallyStream devNull inh
912+ readWriteFinallyStream inh (nullH env)
901− , mkBench "S.finallyIO" href $ do
913+ , mkBenchSmall "S.finallyIO" env $ \inh _ ->
902− Handles inh _ <- readIORef href
903− readWriteFinallyIOStream devNull inh
914+ readWriteFinallyIOStream inh (nullH env)
904 ]
915 ]
905 , bgroup "copy/fromToBytes/exceptions"
916 , bgroup "copy/fromToBytes/exceptions"
906− [ mkBench "S.bracket" href $ do
917+ [ mkBenchSmall "S.bracket" env $ \inh _ ->
907− Handles inh _ <- readIORef href
908− fromToBytesBracketStream devNull inh
918+ fromToBytesBracketStream inh (nullH env)
909− , mkBench "S.bracketIO" href $ do
919+ , mkBenchSmall "S.bracketIO" env $ \inh _ ->
910− Handles inh _ <- readIORef href
911− fromToBytesBracketIOStream devNull inh
920+ fromToBytesBracketIOStream inh (nullH env)
912 ]
921 ]
913 ]
922 ]
914
923
@@ -945,15 +954,12 @@ inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterpose [''Storable]
945-- inspect $ 'copyChunksSplitInterpose `hasNoType` ''Step
954-- inspect $ 'copyChunksSplitInterpose `hasNoType` ''Step
946#endif
955#endif
947
956
948−o_1_space_copy_toChunks_group_ungroup ::
957+o_1_space_copy_toChunks_group_ungroup :: BenchEnv -> [Benchmark]
949− IORef Handles -> Handle -> Int -> [Benchmark]
950−o_1_space_copy_toChunks_group_ungroup href _ _ =
958+o_1_space_copy_toChunks_group_ungroup env =
951 [ bgroup "copy/toChunks/group-ungroup"
959 [ bgroup "copy/toChunks/group-ungroup"
952− [ mkBench "AS.interposeSuffix . AS.splitOnSuffix" href $ do
960+ [ mkBench "AS.interposeSuffix . AS.splitOnSuffix" env $ \inh outh ->
953− Handles inh outh <- readIORef href
954 copyChunksSplitInterposeSuffix inh outh
961 copyChunksSplitInterposeSuffix inh outh
955− , mkBench "AS.interpose . AS.splitOn" href $ do
962+ , mkBenchSmall "AS.interpose . AS.splitOn" env $ \inh outh ->
956− Handles inh outh <- readIORef href
957 copyChunksSplitInterpose inh outh
963 copyChunksSplitInterpose inh outh
958 ]
964 ]
959 ]
965 ]
@@ -1086,29 +1092,22 @@ wordsUnwordsCharArrayCopy inh outh =
1086 $ SS.decodeLatin1
1092 $ SS.decodeLatin1
1087 $ S.unfold FH.read inh
1093 $ S.unfold FH.read inh
1088
1094
1089−o_1_space_copy_read_group_ungroup ::
1095+o_1_space_copy_read_group_ungroup :: BenchEnv -> [Benchmark]
1090− IORef Handles -> Handle -> Int -> [Benchmark]
1091−o_1_space_copy_read_group_ungroup href _ _ =
1096+o_1_space_copy_read_group_ungroup env =
1092 [ bgroup "copy/read/group-ungroup"
1097 [ bgroup "copy/read/group-ungroup"
1093− [ mkBench "US.unlines . S.splitOnSuffix ([Word8])" href $ do
1098+ [ mkBenchSmall "US.unlines . S.splitOnSuffix ([Word8])" env
1094− Handles inh outh <- readIORef href
1095− linesUnlinesCopy inh outh
1099+ $ \inh outh -> linesUnlinesCopy inh outh
1096− , mkBench "S.interposeSuffix . S.splitOnSuffix(Array Word8)" href $ do
1100+ , mkBenchSmall "S.interposeSuffix . S.splitOnSuffix(Array Word8)" env
1097− Handles inh outh <- readIORef href
1098− linesUnlinesArrayWord8Copy inh outh
1101+ $ \inh outh -> linesUnlinesArrayWord8Copy inh outh
1099− , mkBench "UA.unlines . UA.lines (Array Char)" href $ do
1102+ , mkBenchSmall "UA.unlines . UA.lines (Array Char)" env
1100− Handles inh outh <- readIORef href
1101− linesUnlinesArrayCharCopy inh outh
1103+ $ \inh outh -> linesUnlinesArrayCharCopy inh outh
1102−
1104+
1103− , mkBench "S.interposeSuffix . S.wordsBy ([Word8])" href $ do
1105+ , mkBenchSmall "S.interposeSuffix . S.wordsBy ([Word8])" env
1104− Handles inh outh <- readIORef href
1105− wordsUnwordsCopyWord8 inh outh
1106+ $ \inh outh -> wordsUnwordsCopyWord8 inh outh
1106− , mkBench "US.unwords . S.wordsBy ([Char])" href $ do
1107+ , mkBenchSmall "US.unwords . S.wordsBy ([Char])" env
1107− Handles inh outh <- readIORef href
1108− wordsUnwordsCopy inh outh
1108+ $ \inh outh -> wordsUnwordsCopy inh outh
1109− , mkBench "UA.unwords . UA.words (Array Char)" href $ do
1109+ , mkBenchSmall "UA.unwords . UA.words (Array Char)" env
1110− Handles inh outh <- readIORef href
1111− wordsUnwordsCharArrayCopy inh outh
1110+ $ \inh outh -> wordsUnwordsCharArrayCopy inh outh
1112 ]
1111 ]
1113 ]
1112 ]
1114
1113
@@ -1199,66 +1198,45 @@ splitOnSuffixSeq str inh =
1199-- inspect $ 'splitOnSuffixSeq `hasNoType` ''D.ConcatMapUState
1198-- inspect $ 'splitOnSuffixSeq `hasNoType` ''D.ConcatMapUState
1200#endif
1199#endif
1201
1200
1202−o_1_space_reduce_read_split ::
1201+o_1_space_reduce_read_split :: BenchEnv -> [Benchmark]
1203− IORef Handles -> Handle -> Int -> [Benchmark]
1204−o_1_space_reduce_read_split href _ _ =
1202+o_1_space_reduce_read_split env =
1205 [ bgroup "reduce/read"
1203 [ bgroup "reduce/read"
1206− [ mkBench "S.parseMany (PR.sliceSepBy (== lf) FL.drain)" href $ do
1204+ [ mkBench "S.parseMany (PR.sliceSepBy (== lf) FL.drain)" env
1207− Handles inh _ <- readIORef href
1208− parseManySepBy inh
1205+ $ \inh _ -> parseManySepBy inh
1209− , mkBench "S.wordsBy isSpace FL.drain" href $ do
1206+ , mkBench "S.wordsBy isSpace FL.drain" env $ \inh _ ->
1210− Handles inh _ <- readIORef href
1211 wordsBy inh
1207 wordsBy inh
1212− , mkBench "S.splitOn (== lf) FL.drain" href $ do
1208+ , mkBench "S.splitOn (== lf) FL.drain" env $ \inh _ ->
1213− Handles inh _ <- readIORef href
1214 splitOn inh
1209 splitOn inh
1215− , mkBench "S.splitOnSuffix (== lf) FL.drain" href $ do
1210+ , mkBench "S.splitOnSuffix (== lf) FL.drain" env $ \inh _ ->
1216− Handles inh _ <- readIORef href
1217 splitOnSuffix inh
1211 splitOnSuffix inh
1218− , mkBench "S.splitOnSeq \"\" FL.drain" href $ do
1212+ , mkBench "S.splitOnSeq \"\" FL.drain" env $ \inh _ ->
1219− Handles inh _ <- readIORef href
1220 splitOnSeq "" inh
1213 splitOnSeq "" inh
1221− , mkBench "S.splitOnSuffixSeq \"\" FL.drain" href $ do
1214+ , mkBench "S.splitOnSuffixSeq \"\" FL.drain" env $ \inh _ ->
1222− Handles inh _ <- readIORef href
1223 splitOnSuffixSeq "" inh
1215 splitOnSuffixSeq "" inh
1224− , mkBench "S.splitOnSeq \"\\n\" FL.drain" href $ do
1216+ , mkBench "S.splitOnSeq \"\\n\" FL.drain" env $ \inh _ ->
1225− Handles inh _ <- readIORef href
1226 splitOnSeq "\n" inh
1217 splitOnSeq "\n" inh
1227− , mkBench "S.splitOnSuffixSeq \"\\n\" FL.drain" href $ do
1218+ , mkBench "S.splitOnSuffixSeq \"\\n\" FL.drain" env $ \inh _ ->
1228− Handles inh _ <- readIORef href
1229 splitOnSuffixSeq "\n" inh
1219 splitOnSuffixSeq "\n" inh
1230− , mkBench "S.splitOnSeq \"a\" FL.drain" href $ do
1220+ , mkBench "S.splitOnSeq \"a\" FL.drain" env $ \inh _ ->
1231− Handles inh _ <- readIORef href
1232 splitOnSeq "a" inh
1221 splitOnSeq "a" inh
1233− , mkBench "S.splitOnSeq \"\\r\\n\" FL.drain" href $ do
1222+ , mkBench "S.splitOnSeq \"\\r\\n\" FL.drain" env $ \inh _ ->
1234− Handles inh _ <- readIORef href
1235 splitOnSeq "\r\n" inh
1223 splitOnSeq "\r\n" inh
1236− , mkBench "S.splitOnSuffixSeq \"\\r\\n\" FL.drain" href $ do
1224+ , mkBench "S.splitOnSuffixSeq \"\\r\\n\" FL.drain" env $ \inh _ ->
1237− Handles inh _ <- readIORef href
1238 splitOnSuffixSeq "\r\n" inh
1225 splitOnSuffixSeq "\r\n" inh
1239− , mkBench "S.splitOnSeq \"aa\" FL.drain" href $ do
1226+ , mkBench "S.splitOnSeq \"aa\" FL.drain" env $ \inh _ ->
1240− Handles inh _ <- readIORef href
1241 splitOnSeq "aa" inh
1227 splitOnSeq "aa" inh
1242− , mkBench "S.splitOnSeq \"aaaa\" FL.drain" href $ do
1228+ , mkBench "S.splitOnSeq \"aaaa\" FL.drain" env $ \inh _ ->
1243− Handles inh _ <- readIORef href
1244 splitOnSeq "aaaa" inh
1229 splitOnSeq "aaaa" inh
1245− , mkBench "S.splitOnSeq \"abcdefgh\" FL.drain" href $ do
1230+ , mkBench "S.splitOnSeq \"abcdefgh\" FL.drain" env $ \inh _ ->
1246− Handles inh _ <- readIORef href
1247 splitOnSeq "abcdefgh" inh
1231 splitOnSeq "abcdefgh" inh
1248− , mkBench "S.splitOnSeq \"abcdefghi\" FL.drain" href $ do
1232+ , mkBench "S.splitOnSeq \"abcdefghi\" FL.drain" env $ \inh _ ->
1249− Handles inh _ <- readIORef href
1250 splitOnSeq "abcdefghi" inh
1233 splitOnSeq "abcdefghi" inh
1251− , mkBench "S.splitOnSeq \"catcatcatcatcat\" FL.drain" href $ do
1234+ , mkBench "S.splitOnSeq \"catcatcatcatcat\" FL.drain" env $ \inh _ ->
1252− Handles inh _ <- readIORef href
1253 splitOnSeq "catcatcatcatcat" inh
1235 splitOnSeq "catcatcatcatcat" inh
1254 , mkBench "S.splitOnSeq \"abcdefghijklmnopqrstuvwxyz\" FL.drain"
1236 , mkBench "S.splitOnSeq \"abcdefghijklmnopqrstuvwxyz\" FL.drain"
1255− href $ do
1256− Handles inh _ <- readIORef href
1257− splitOnSeq "abcdefghijklmnopqrstuvwxyz" inh
1237+ env $ \inh _ -> splitOnSeq "abcdefghijklmnopqrstuvwxyz" inh
1258− , mkBench "S.splitOnSuffixSeq \"abcdefghijklmnopqrstuvwxyz\" FL.drain"
1238+ , mkBenchSmall "S.splitOnSuffixSeq \"abcdefghijklmnopqrstuvwxyz\" FL.drain"
1259− href $ do
1260− Handles inh _ <- readIORef href
1261− splitOnSuffixSeq "abcdefghijklmnopqrstuvwxyz" inh
1239+ env $ \inh _ -> splitOnSuffixSeq "abcdefghijklmnopqrstuvwxyz" inh
1262 ]
1240 ]
1263 ]
1241 ]
1264
1242
@@ -1270,18 +1248,14 @@ splitOnSeqUtf8 str inh =
1270 $ IUS.decodeUtf8ArraysLenient
1248 $ IUS.decodeUtf8ArraysLenient
1271 $ IFH.toChunks inh) -- >>= print
1249 $ IFH.toChunks inh) -- >>= print
1272
1250
1273−o_1_space_reduce_toChunks_split ::
1251+o_1_space_reduce_toChunks_split :: BenchEnv -> [Benchmark]
1274− IORef Handles -> Handle -> Int -> [Benchmark]
1275−o_1_space_reduce_toChunks_split href _ _ =
1252+o_1_space_reduce_toChunks_split env =
1276 [ bgroup "reduce/toChunks"
1253 [ bgroup "reduce/toChunks"
1277− [ mkBench ("S.splitOnSeqUtf8 \"abcdefgh\" FL.drain "
1254+ [ mkBenchSmall ("S.splitOnSeqUtf8 \"abcdefgh\" FL.drain "
1278− ++ ". US.decodeUtf8ArraysLenient") href $ do
1255+ ++ ". US.decodeUtf8ArraysLenient") env $ \inh _ ->
1279− Handles inh _ <- readIORef href
1280 splitOnSeqUtf8 "abcdefgh" inh
1256 splitOnSeqUtf8 "abcdefgh" inh
1281− , mkBench "S.splitOnSeqUtf8 \"abcdefghijklmnopqrstuvwxyz\" FL.drain"
1257+ , mkBenchSmall "S.splitOnSeqUtf8 \"abcdefghijklmnopqrstuvwxyz\" FL.drain"
1282− href $ do
1283− Handles inh _ <- readIORef href
1284− splitOnSeqUtf8 "abcdefghijklmnopqrstuvwxyz" inh
1258+ env $ \inh _ -> splitOnSeqUtf8 "abcdefghijklmnopqrstuvwxyz" inh
1285 ]
1259 ]
1286 ]
1260 ]
1287
1261
@@ -1292,13 +1266,8 @@ o_1_space_reduce_toChunks_split href _ _ =
1292main :: IO ()
1266main :: IO ()
1293main = do
1267main = do
1294 (_, cfg, benches) <- parseCLIOpts defaultStreamSize
1268 (_, cfg, benches) <- parseCLIOpts defaultStreamSize
1295−
1296− -- XXX The file is cached, so if the older file was a different size it
1297− -- will not be correct
1298− -- fileSize = blockSize * blockCount
1299−
1300 r <- lookupEnv "Benchmark.FileSystem.Handle.InputFile"
1269 r <- lookupEnv "Benchmark.FileSystem.Handle.InputFile"
1301− (_, big) <-
1270+ (small, big) <-
1302 case r of
1271 case r of
1303 Just inFileName -> return (inFileName, inFileName)
1272 Just inFileName -> return (inFileName, inFileName)
1304 Nothing -> do
1273 Nothing -> do
@@ -1315,37 +1284,54 @@ main = do
1315 runProcess_ (shell (cmd inFileBig bigFileSize))
1284 runProcess_ (shell (cmd inFileBig bigFileSize))
1316 return (inFileSmall, inFileBig)
1285 return (inFileSmall, inFileBig)
1317
1286
1318− -- smallHandle <- openFile small ReadMode
1287+ smallHandle <- openFile small ReadMode
1319 bigHandle <- openFile big ReadMode
1288 bigHandle <- openFile big ReadMode
1320 outHandle <- openFile outfile WriteMode
1289 outHandle <- openFile outfile WriteMode
1321 devNull <- openFile "/dev/null" WriteMode
1290 devNull <- openFile "/dev/null" WriteMode
1322
1291
1292+#if __GLASGOW_HASKELL__ >= 800
1323− -- ssize <- getFileSize small
1293+ ssize <- fromIntegral <$> getFileSize small
1324− bsize <- getFileSize big
1294+ bsize <- fromIntegral <$> getFileSize big
1295+#else
1296+ let ssize = smallFileSize
1297+ let bsize = bigFileSize
1298+#endif
1299+
1300+ ref <- newIORef $ RefHandles
1301+ { smallInH = smallHandle
1302+ , bigInH = bigHandle
1303+ , outputH = outHandle
1304+ }
1305+
1306+ let env = BenchEnv
1307+ { href = ref
1308+ , smallSize = ssize
1309+ , bigSize = bsize
1310+ , nullH = devNull
1311+ }
1325
1312
1326− ref <- newIORef $ Handles bigHandle outHandle
1327− runMode (mode cfg) cfg benches (allBenchmarks ref devNull (fromIntegral bsize))
1313+ runMode (mode cfg) cfg benches (allBenchmarks env)
1328
1314
1329 where
1315 where
1330
1316
1331− allBenchmarks env devNull bsize =
1317+ allBenchmarks env =
1332 [ bgroup (o_1_space_prefix moduleName) $ Prelude.concat
1318 [ bgroup (o_1_space_prefix moduleName) $ Prelude.concat
1333− [ o_1_space_read_chunked env devNull bsize
1319+ [ o_1_space_read_chunked env
1334− , o_1_space_copy_chunked env devNull bsize
1320+ , o_1_space_copy_chunked env
1335− , o_1_space_copy_exceptions_readChunks env devNull bsize
1321+ , o_1_space_copy_exceptions_readChunks env
1336− , o_1_space_copy_exceptions_toChunks env devNull bsize
1322+ , o_1_space_copy_exceptions_toChunks env
1337−
1323+
1338− , o_1_space_reduce_read env devNull bsize
1324+ , o_1_space_reduce_read env
1339− , o_1_space_reduce_toBytes env devNull bsize
1325+ , o_1_space_reduce_toBytes env
1340− , o_1_space_reduce_read_grouped env devNull bsize
1326+ , o_1_space_reduce_read_grouped env
1341− , o_1_space_reduce_read_split env devNull bsize
1327+ , o_1_space_reduce_read_split env
1342− , o_1_space_reduce_toChunks_split env devNull bsize
1328+ , o_1_space_reduce_toChunks_split env
1343−
1329+
1344− , o_1_space_copy_read env devNull bsize
1330+ , o_1_space_copy_read env
1345− , o_1_space_copy_fromBytes env devNull bsize
1331+ , o_1_space_copy_fromBytes env
1346− , o_1_space_copy_read_exceptions env devNull bsize
1332+ , o_1_space_copy_read_exceptions env
1347− , o_1_space_copy_stream_exceptions env devNull bsize
1333+ , o_1_space_copy_stream_exceptions env
1334+ , o_1_space_copy_toChunks_group_ungroup env
1348− , o_1_space_copy_read_group_ungroup env devNull bsize
1335+ , o_1_space_copy_read_group_ungroup env
1349− , o_1_space_copy_toChunks_group_ungroup env devNull bsize
1350 ]
1336 ]
1351 ]
1337 ]