on master help sign in
Bigger buffer -> better performance

--HG-- extra : convert_revision : a7b19b3b7c7dfb094391e946ee8774b483685267

commit040aafa30d3ed278decfbf6f6fb8200ad8fb7148 authorBryan O'Sullivan <bos@serpentine.com> dateSun 15 Aug 2010, 06:19 (16 years ago) parentf7b8c88
1 file changed+18−15
tests/benchmarks/FileRead.hs+18−15
tests/benchmarks/FileRead.hs+18−15
@@ -7,29 +7,32 @@ import qualified Data.Text.Lazy.Encoding as T
77import qualified Data.ByteString.Lazy.Char8 as B
88import qualified Data.ByteString.Char8 as BS
99import qualified Data.ByteString.Lazy.Search as B
10+import System.IO
1011
11−string :: FilePath -> IO ()
12−string file = readFile file >>= print . length
12+string :: Handle -> IO ()
13+string h = hGetContents h >>= print . length
1314
14−text :: FilePath -> IO ()
15−text file = do
16− t <- {-# SCC "T.readFile" #-} T.readFile file
15+text :: Handle -> IO ()
16+text h = do
17+ t <- {-# SCC "T.hGetContents" #-} T.hGetContents h
1718 print (T.length t)
1819
19−textBS :: FilePath -> IO ()
20−textBS file = do
21− bs <- {-# SCC "B.readFile" #-} B.readFile file
20+textBS :: Handle -> IO ()
21+textBS h = do
22+ bs <- {-# SCC "B.hGetContents" #-} B.hGetContents h
2223 print . T.length . T.decodeUtf8 $ bs
2324
24−bytestring :: FilePath -> IO ()
25−bytestring file = do
26− bs <- {-# SCC "B.readFile" #-}B.readFile file
25+bytestring :: Handle -> IO ()
26+bytestring h = do
27+ bs <- {-# SCC "B.hGetContents" #-} B.hGetContents h
2728 print (B.length bs)
2829
2930main = do
3031 (name : file : _) <- getArgs
32+ h <- openFile file ReadMode
33+ hSetBuffering h (BlockBuffering (Just 16384))
3134 case name of
32− "bs" -> bytestring file
33− "string" -> string file
34− "text" -> text file
35− "textBS" -> textBS file
35+ "bs" -> bytestring h
36+ "string" -> string h
37+ "text" -> text h
38+ "textBS" -> textBS h