@@ -20,18 +20,35 @@ import qualified Data.ByteString.Lazy as LB
2020import qualified Data.Text as T
2121import qualified Data.Text.Lazy as LT
2222import qualified Data.Text.Lazy.Builder as LTB
23+import qualified Data.Text.Lazy.Builder.Int as Int
2324
2425benchmark :: IO Benchmark
2526benchmark = return $ bgroup "Builder"
26− [ bench "LazyText" $ nf
27− (LT.length . LTB.toLazyText . mconcat . map LTB.fromText) texts
28− , bench "Binary" $ nf
29− (LB.length . B.toLazyByteString . mconcat . map B.fromByteString)
30− byteStrings
31− , bench "Blaze" $ nf
32− (LB.length . Blaze.toLazyByteString . mconcat . map Blaze.fromString)
33− strings
27+ [ bgroup "Comparison"
28+ [ bench "LazyText" $ nf
29+ (LT.length . LTB.toLazyText . mconcat . map LTB.fromText) texts
30+ , bench "Binary" $ nf
31+ (LB.length . B.toLazyByteString . mconcat . map B.fromByteString)
32+ byteStrings
33+ , bench "Blaze" $ nf
34+ (LB.length . Blaze.toLazyByteString . mconcat . map Blaze.fromString)
35+ strings
36+ ]
37+ , bgroup "Int"
38+ [ bgroup "Decimal"
39+ [ bgroup "Positive" .
40+ flip map numbers $ \n ->
41+ (bench (show n) $ nf (LTB.toLazyText . Int.decimal) n)
42+ , bgroup "Negative" .
43+ flip map numbers $ \m ->
44+ let n = negate m in
45+ (bench (show n) $ nf (LTB.toLazyText . Int.decimal) n)
46+ ]
47+ ]
3448 ]
49+ where
50+ numbers = [6,1,14,93,500,415,9688,2865,10654,30214,795659,829056,6207351,
51+ 5608880,33929478,96076286,370106126,731223504] :: [Int]
3552
3653texts :: [T.Text]
3754texts = take 200000 $ cycle ["foo", "λx", "由の"]