Jasper Van der Jeugt avatar Jasper Van der Jeugt committed 0ecd86e

Consistently use ByteString's for IO

Comments (0)

Files changed (3)

tests/benchmarks/src/Data/Text/Benchmarks/Programs/Sort.hs

 import Data.Monoid (mconcat)
 import System.IO (Handle, hPutStr)
 import qualified Data.ByteString as B
+import qualified Data.ByteString.Char8 as BC
 import qualified Data.ByteString.Lazy as BL
 import qualified Data.ByteString.Lazy.Char8 as BLC
-import qualified Data.ByteString.Char8 as BC
 import qualified Data.List as L
 import qualified Data.Text as T
+import qualified Data.Text.Encoding as T
 import qualified Data.Text.IO as T
 import qualified Data.Text.Lazy as TL
+import qualified Data.Text.Lazy.Builder as TLB
+import qualified Data.Text.Lazy.Encoding as TL
 import qualified Data.Text.Lazy.IO as TL
-import qualified Data.Text.Lazy.Builder as TLB
 
 benchmark :: FilePath -> Handle -> IO Benchmark
 benchmark i o = return $ bgroup "Sort"
     , bench "LazyByteString" $ BL.readFile i >>= BL.hPutStr o . lazyByteString
     , bench "Text" $ T.readFile i >>= T.hPutStr o . text
     , bench "LazyText" $ TL.readFile i >>= TL.hPutStr o . lazyText
-    , bench "TextBuilder" $ T.readFile i >>= TL.hPutStr o . textBuilder
+    , bench "TextByteString" $ B.readFile i >>=
+        B.hPutStr o . T.encodeUtf8 . text . T.decodeUtf8
+    , bench "LazyTextByteString" $ BL.readFile i >>=
+        BL.hPutStr o . TL.encodeUtf8 . lazyText .  TL.decodeUtf8
+    , bench "TextBuilder" $ B.readFile i >>=
+        BL.hPutStr o . TL.encodeUtf8 . textBuilder . T.decodeUtf8
     ]
 
 string :: String -> String

tests/benchmarks/src/Data/Text/Benchmarks/Programs/StripTags.hs

 import qualified Data.ByteString.Char8 as BC
 import qualified Data.Text as T
 import qualified Data.Text.Encoding as T
+import qualified Data.Text.IO as T
 
 benchmark :: FilePath -> Handle -> IO Benchmark
 benchmark i o = return $ bgroup "StripTags"
     [ bench "String" $ readFile i >>= hPutStr o . string
     , bench "ByteString" $ B.readFile i >>= B.hPutStr o . byteString
-    , bench "Text" $
+    , bench "Text" $ T.readFile i >>= T.hPutStr o . text
+    , bench "TextByteString" $
         B.readFile i >>= B.hPutStr o . T.encodeUtf8 . text . T.decodeUtf8
     ]
 

tests/benchmarks/src/Data/Text/Benchmarks/Programs/Throughput.hs

 import System.IO (Handle, hPutStr)
 import qualified Data.ByteString as B
 import qualified Data.ByteString.Lazy as BL
+import qualified Data.Text.Encoding as T
 import qualified Data.Text.IO as T
+import qualified Data.Text.Lazy.Encoding as TL
 import qualified Data.Text.Lazy.IO as TL
 
 benchmark :: FilePath -> Handle -> IO Benchmark
     , bench "LazyByteString" $ BL.readFile fp >>= BL.hPutStr sink
     , bench "Text" $ T.readFile fp >>= T.hPutStr sink
     , bench "LazyText" $ TL.readFile fp >>= TL.hPutStr sink
+    , bench "TextByteString" $
+        B.readFile fp >>= B.hPutStr sink . T.encodeUtf8 .  T.decodeUtf8
+    , bench "LazyTextByteString" $
+        BL.readFile fp >>= BL.hPutStr sink . TL.encodeUtf8 . TL.decodeUtf8
     ]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.