on master help sign in
Add lazy and strict variants
77482f5Bryan O'Sullivan
tests/benchmarks/FileRead.hs+26−6
@@ -1,17 +1,29 @@
1{-# LANGUAGE BangPatterns #-}
1{-# LANGUAGE BangPatterns #-}
2
2
3import System.Environment (getArgs)
3import System.Environment (getArgs)
4−import qualified Data.Text.Lazy.IO as T
4+import qualified Data.Text.IO as T
5−import qualified Data.Text.Lazy as T
5+import qualified Data.Text as T
6+import qualified Data.Text.Encoding as T
6−import qualified Data.Text.Lazy.Encoding as T
7+import qualified Data.Text.Lazy.IO as TL
8+import qualified Data.Text.Lazy as TL
7−import qualified Data.ByteString.Lazy.Char8 as B
9+import qualified Data.Text.Lazy.Encoding as TL
8−import qualified Data.ByteString.Char8 as BS
10+import qualified Data.ByteString.Char8 as B
9−import qualified Data.ByteString.Lazy.Search as B
11+import qualified Data.ByteString.Lazy.Char8 as BL
10import System.IO
12import System.IO
11
13
12string :: Handle -> IO ()
14string :: Handle -> IO ()
13string h = hGetContents h >>= print . length
15string h = hGetContents h >>= print . length
14
16
17+ltext :: Handle -> IO ()
18+ltext h = do
19+ t <- {-# SCC "TL.hGetContents" #-} TL.hGetContents h
20+ print (TL.length t)
21+
22+ltextBS :: Handle -> IO ()
23+ltextBS h = do
24+ bs <- {-# SCC "B.hGetContents" #-} BL.hGetContents h
25+ print . TL.length . TL.decodeUtf8 $ bs
26+
15text :: Handle -> IO ()
27text :: Handle -> IO ()
16text h = do
28text h = do
17 t <- {-# SCC "T.hGetContents" #-} T.hGetContents h
29 t <- {-# SCC "T.hGetContents" #-} T.hGetContents h
@@ -22,6 +34,11 @@ textBS h = do
22 bs <- {-# SCC "B.hGetContents" #-} B.hGetContents h
34 bs <- {-# SCC "B.hGetContents" #-} B.hGetContents h
23 print . T.length . T.decodeUtf8 $ bs
35 print . T.length . T.decodeUtf8 $ bs
24
36
37+lbytestring :: Handle -> IO ()
38+lbytestring h = do
39+ bs <- {-# SCC "BL.hGetContents" #-} BL.hGetContents h
40+ print (BL.length bs)
41+
25bytestring :: Handle -> IO ()
42bytestring :: Handle -> IO ()
26bytestring h = do
43bytestring h = do
27 bs <- {-# SCC "B.hGetContents" #-} B.hGetContents h
44 bs <- {-# SCC "B.hGetContents" #-} B.hGetContents h
@@ -33,6 +50,9 @@ main = do
33 hSetBuffering h (BlockBuffering (Just 16384))
50 hSetBuffering h (BlockBuffering (Just 16384))
34 case name of
51 case name of
35 "bs" -> bytestring h
52 "bs" -> bytestring h
53+ "lbs" -> lbytestring h
54+ "ltext" -> ltext h
55+ "ltextBS" -> ltextBS h
36 "string" -> string h
56 "string" -> string h
37 "text" -> text h
57 "text" -> text h
38 "textBS" -> textBS h
58 "textBS" -> textBS h