@@ -0,0 +1,27 @@
1+-- | This benchmark simply reads and writes a file using the various string
2+-- libraries. The point of it is that we can make better estimations on how
3+-- much time the other benchmarks spend doing IO.
5+-- Note that we expect ByteStrings to be a whole lot faster, since they do not
6+-- do any actual encoding/decoding here, while String and Text do have UTF-8
9+module Data.Text.Benchmarks.Programs.Throughput
13+import Criterion (Benchmark, bgroup, bench)
14+import System.IO (Handle, hPutStr)
15+import qualified Data.ByteString as B
16+import qualified Data.ByteString.Lazy as BL
17+import qualified Data.Text.IO as T
18+import qualified Data.Text.Lazy.IO as TL
20+benchmark :: FilePath -> Handle -> IO Benchmark
21+benchmark fp sink = return $ bgroup "Throughput"
22+ [ bench "String" $ readFile fp >>= hPutStr sink
23+ , bench "ByteString" $ B.readFile fp >>= B.hPutStr sink
24+ , bench "LazyByteString" $ BL.readFile fp >>= BL.hPutStr sink
25+ , bench "Text" $ T.readFile fp >>= T.hPutStr sink
26+ , bench "LazyText" $ TL.readFile fp >>= TL.hPutStr sink