@@ -20,18 +20,35 @@ import qualified Data.ByteString.Lazy as LB
20import qualified Data.Text as T
20import qualified Data.Text as T
21import qualified Data.Text.Lazy as LT
21import qualified Data.Text.Lazy as LT
22import qualified Data.Text.Lazy.Builder as LTB
22import qualified Data.Text.Lazy.Builder as LTB
23+import qualified Data.Text.Lazy.Builder.Int as Int
24benchmark :: IO Benchmark
25benchmark :: IO Benchmark
25benchmark = return $ bgroup "Builder"
26benchmark = return $ bgroup "Builder"
27+ [ bgroup "Comparison"
26− [ bench "LazyText" $ nf
28+ [ bench "LazyText" $ nf
27− (LT.length . LTB.toLazyText . mconcat . map LTB.fromText) texts
29+ (LT.length . LTB.toLazyText . mconcat . map LTB.fromText) texts
28− , bench "Binary" $ nf
30+ , bench "Binary" $ nf
29− (LB.length . B.toLazyByteString . mconcat . map B.fromByteString)
31+ (LB.length . B.toLazyByteString . mconcat . map B.fromByteString)
30− byteStrings
32+ byteStrings
31− , bench "Blaze" $ nf
33+ , bench "Blaze" $ nf
32− (LB.length . Blaze.toLazyByteString . mconcat . map Blaze.fromString)
34+ (LB.length . Blaze.toLazyByteString . mconcat . map Blaze.fromString)
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 ->
45+ (bench (show n) $ nf (LTB.toLazyText . Int.decimal) n)
50+ numbers = [6,1,14,93,500,415,9688,2865,10654,30214,795659,829056,6207351,
51+ 5608880,33929478,96076286,370106126,731223504] :: [Int]
36texts :: [T.Text]
53texts :: [T.Text]
37texts = take 200000 $ cycle ["foo", "λx", "由の"]
54texts = take 200000 $ cycle ["foo", "λx", "由の"]