on master help sign in
Add Throughput benchmark
commitd8ce04359ba2a370c56c2cfa3f31c0d88624de52 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSat 4 Jun 2011, 09:08 (15 years ago) parent4b5153d
2 files changed+29
tests/benchmarks/src/Data/Text/Benchmarks.hs+2 tests/benchmarks/src/Data/Text/Benchmarks/Programs/Throughput.hs+27
tests/benchmarks/src/Data/Text/Benchmarks.hs+2
@@ -26,6 +26,7 @@ import qualified Data.Text.Benchmarks.StripBrackets as StripBrackets
2626import qualified Data.Text.Benchmarks.WordCount as WordCount
2727
2828import qualified Data.Text.Benchmarks.Programs.Cut as Programs.Cut
29+import qualified Data.Text.Benchmarks.Programs.Throughput as Programs.Throughput
2930
3031main :: IO ()
3132main = benchmarks >>= defaultMain
@@ -57,6 +58,7 @@ benchmarks = do
5758 -- Program-like benchmarks
5859 ps <- bgroup "Programs" `fmap` sequence
5960 [ Programs.Cut.benchmark (tf "russian.txt") sink 20 40
61+ , Programs.Throughput.benchmark (tf "russian.txt") sink
6062 ]
6163
6264 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+ ]