on master help sign in
Add benchmarks for gh-165

I used the code from the gist as the source for the Concat module.

commit2e73fe2d0e92b22201cecc6b21514a164c4c974e authorBryan O'Sullivan <bos@serpentine.com> dateMon 7 Aug 2017, 20:33 (9 years ago) parent45f389b
3 files changed+28
benchmarks/haskell/Benchmarks.hs+2 benchmarks/haskell/Benchmarks/Concat.hs+25 benchmarks/text-benchmarks.cabal+1
benchmarks/haskell/Benchmarks.hs+2
@@ -10,6 +10,7 @@ import System.FilePath ((</>))
1010import System.IO (IOMode (WriteMode), openFile, hSetEncoding, utf8)
1111
1212import qualified Benchmarks.Builder as Builder
13+import qualified Benchmarks.Concat as Concat
1314import qualified Benchmarks.DecodeUtf8 as DecodeUtf8
1415import qualified Benchmarks.EncodeUtf8 as EncodeUtf8
1516import qualified Benchmarks.Equality as Equality
@@ -41,6 +42,7 @@ benchmarks = do
4142 -- Traditional benchmarks
4243 bs <- sequence
4344 [ Builder.benchmark
45+ , Concat.benchmark
4446 , DecodeUtf8.benchmark "html" (tf "libya-chinese.html")
4547 , DecodeUtf8.benchmark "xml" (tf "yiwiki.xml")
4648 , DecodeUtf8.benchmark "ascii" (tf "ascii.txt")
benchmarks/haskell/Benchmarks/Concat.hsnew file+25
@@ -0,0 +1,25 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+
3+module Benchmarks.Concat (benchmark) where
4+
5+import Control.Monad.Trans.Writer
6+import Criterion (Benchmark, bgroup, bench, whnf)
7+import Data.Text as T
8+
9+benchmark :: IO Benchmark
10+benchmark = return $ bgroup "Concat"
11+ [ bench "append" $ whnf (append4 "Text 1" "Text 2" "Text 3") "Text 4"
12+ , bench "concat" $ whnf (concat4 "Text 1" "Text 2" "Text 3") "Text 4"
13+ , bench "write" $ whnf (write4 "Text 1" "Text 2" "Text 3") "Text 4"
14+ ]
15+
16+append4, concat4, write4 :: Text -> Text -> Text -> Text -> Text
17+
18+{-# NOINLINE append4 #-}
19+append4 x1 x2 x3 x4 = x1 `append` x2 `append` x3 `append` x4
20+
21+{-# NOINLINE concat4 #-}
22+concat4 x1 x2 x3 x4 = T.concat [x1, x2, x3, x4]
23+
24+{-# NOINLINE write4 #-}
25+write4 x1 x2 x3 x4 = execWriter $ tell x1 >> tell x2 >> tell x3 >> tell x4
benchmarks/text-benchmarks.cabal+1
@@ -47,6 +47,7 @@ executable text-benchmarks
4747 ghc-prim,
4848 integer-gmp,
4949 stringsearch,
50+ transformers,
5051 utf8-string,
5152 vector
5253