on master help sign in
Benchmark decimal integer rendering
b30b442Bryan O'Sullivan
benchmarks/haskell/Benchmarks/Builder.hs+25−8
@@ -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
23
24
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)
33− strings
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+ ]
34 ]
48 ]
49+ where
50+ numbers = [6,1,14,93,500,415,9688,2865,10654,30214,795659,829056,6207351,
51+ 5608880,33929478,96076286,370106126,731223504] :: [Int]
35
52
36texts :: [T.Text]
53texts :: [T.Text]
37texts = take 200000 $ cycle ["foo", "λx", "由の"]
54texts = take 200000 $ cycle ["foo", "λx", "由の"]
benchmarks/text-benchmarks.cabal+2−1
@@ -21,7 +21,7 @@ executable text-benchmarks
21 cbits/time_iconv.c
21 cbits/time_iconv.c
22 main-is: Benchmarks.hs
22 main-is: Benchmarks.hs
23 ghc-options: -Wall -O2
23 ghc-options: -Wall -O2
24− cpp-options: -DHAVE_DEEPSEQ
24+ cpp-options: -DHAVE_DEEPSEQ -DINTEGER_GMP
25 build-depends: base == 4.*,
25 build-depends: base == 4.*,
26 binary,
26 binary,
27 blaze-builder,
27 blaze-builder,
@@ -33,6 +33,7 @@ executable text-benchmarks
33 directory,
33 directory,
34 filepath,
34 filepath,
35 ghc-prim,
35 ghc-prim,
36+ integer-gmp,
36 stringsearch,
37 stringsearch,
37 utf8-string
38 utf8-string
38
39