Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Consistently use ByteString's for IO

  • Loading branch information...
commit 1b33e0812bf036b250c094d3c39df1b6351af890 1 parent b90f89b
@jaspervdj jaspervdj authored
View
13 tests/benchmarks/src/Data/Text/Benchmarks/Programs/Sort.hs
@@ -21,15 +21,17 @@ import Criterion (Benchmark, bgroup, bench)
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.IO 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
benchmark :: FilePath -> Handle -> IO Benchmark
benchmark i o = return $ bgroup "Sort"
@@ -38,7 +40,12 @@ 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
View
4 tests/benchmarks/src/Data/Text/Benchmarks/Programs/StripTags.hs
@@ -22,12 +22,14 @@ import qualified Data.ByteString as B
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
]
View
6 tests/benchmarks/src/Data/Text/Benchmarks/Programs/Throughput.hs
@@ -22,7 +22,9 @@ import Criterion (Benchmark, bgroup, bench)
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
@@ -32,4 +34,8 @@ benchmark fp sink = return $ bgroup "Throughput"
, 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
]
Please sign in to comment.
Something went wrong with that request. Please try again.