on master help sign in
Add Throughput benchmark
d8ce043Jasper Van der Jeugt
tests/benchmarks/src/Data/Text/Benchmarks.hs+2
@@ -26,6 +26,7 @@ import qualified Data.Text.Benchmarks.StripBrackets as StripBrackets
26import qualified Data.Text.Benchmarks.WordCount as WordCount
26import qualified Data.Text.Benchmarks.WordCount as WordCount
27
27
28import qualified Data.Text.Benchmarks.Programs.Cut as Programs.Cut
28import qualified Data.Text.Benchmarks.Programs.Cut as Programs.Cut
29+import qualified Data.Text.Benchmarks.Programs.Throughput as Programs.Throughput
29
30
30main :: IO ()
31main :: IO ()
31main = benchmarks >>= defaultMain
32main = benchmarks >>= defaultMain
@@ -57,6 +58,7 @@ benchmarks = do
57 -- Program-like benchmarks
58 -- Program-like benchmarks
58 ps <- bgroup "Programs" `fmap` sequence
59 ps <- bgroup "Programs" `fmap` sequence
59 [ Programs.Cut.benchmark (tf "russian.txt") sink 20 40
60 [ Programs.Cut.benchmark (tf "russian.txt") sink 20 40
61+ , Programs.Throughput.benchmark (tf "russian.txt") sink
60 ]
62 ]
61
63
62 return $ bs ++ [ps]
64 return $ bs ++ [ps]
tests/benchmarks/src/Data/Text/Benchmarks/Programs/Throughput.hsnew file+27
@@ -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.
4+--
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
7+-- encoding/decoding.
8+--
9+module Data.Text.Benchmarks.Programs.Throughput
10+ ( benchmark
11+ ) where
12+
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
19+
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
27+ ]