on master help sign in
Benchmark decimal integer rendering
commitb30b4427063aaa38c2a50d3fe58726d7e32ba616 authorBryan O'Sullivan <bos@serpentine.com> dateMon 18 Mar 2013, 21:35 (14 years ago) parent779189d
2 files changed+27−9
benchmarks/haskell/Benchmarks/Builder.hs+25−8 benchmarks/text-benchmarks.cabal+2−1
benchmarks/haskell/Benchmarks/Builder.hs+25−8
@@ -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", "由の"]
benchmarks/text-benchmarks.cabal+2−1
@@ -21,7 +21,7 @@ executable text-benchmarks
2121 cbits/time_iconv.c
2222 main-is: Benchmarks.hs
2323 ghc-options: -Wall -O2
24− cpp-options: -DHAVE_DEEPSEQ
24+ cpp-options: -DHAVE_DEEPSEQ -DINTEGER_GMP
2525 build-depends: base == 4.*,
2626 binary,
2727 blaze-builder,
@@ -33,6 +33,7 @@ executable text-benchmarks
3333 directory,
3434 filepath,
3535 ghc-prim,
36+ integer-gmp,
3637 stringsearch,
3738 utf8-string
3839