on master help sign in
Add lazy and strict variants

--HG-- extra : convert_revision : 3cedffd1934167c1e024ca841d144c9487607c7f

commit77482f525ecbeb8284270115ce7d206ccec60d6b authorBryan O'Sullivan <bos@serpentine.com> dateSun 15 Aug 2010, 06:32 (16 years ago) parent8948cdb
1 file changed+26−6
tests/benchmarks/FileRead.hs+26−6
tests/benchmarks/FileRead.hs+26−6
@@ -1,17 +1,29 @@
11{-# LANGUAGE BangPatterns #-}
22
33import System.Environment (getArgs)
4−import qualified Data.Text.Lazy.IO as T
5−import qualified Data.Text.Lazy as T
6−import qualified Data.Text.Lazy.Encoding as T
7−import qualified Data.ByteString.Lazy.Char8 as B
8−import qualified Data.ByteString.Char8 as BS
9−import qualified Data.ByteString.Lazy.Search as B
4+import qualified Data.Text.IO as T
5+import qualified Data.Text as T
6+import qualified Data.Text.Encoding as T
7+import qualified Data.Text.Lazy.IO as TL
8+import qualified Data.Text.Lazy as TL
9+import qualified Data.Text.Lazy.Encoding as TL
10+import qualified Data.ByteString.Char8 as B
11+import qualified Data.ByteString.Lazy.Char8 as BL
1012import System.IO
1113
1214string :: Handle -> IO ()
1315string h = hGetContents h >>= print . length
1416
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+
1527text :: Handle -> IO ()
1628text h = do
1729 t <- {-# SCC "T.hGetContents" #-} T.hGetContents h
@@ -22,6 +34,11 @@ textBS h = do
2234 bs <- {-# SCC "B.hGetContents" #-} B.hGetContents h
2335 print . T.length . T.decodeUtf8 $ bs
2436
37+lbytestring :: Handle -> IO ()
38+lbytestring h = do
39+ bs <- {-# SCC "BL.hGetContents" #-} BL.hGetContents h
40+ print (BL.length bs)
41+
2542bytestring :: Handle -> IO ()
2643bytestring h = do
2744 bs <- {-# SCC "B.hGetContents" #-} B.hGetContents h
@@ -33,6 +50,9 @@ main = do
3350 hSetBuffering h (BlockBuffering (Just 16384))
3451 case name of
3552 "bs" -> bytestring h
53+ "lbs" -> lbytestring h
54+ "ltext" -> ltext h
55+ "ltextBS" -> ltextBS h
3656 "string" -> string h
3757 "text" -> text h
3858 "textBS" -> textBS h