on master help sign in
Backport integer builder benchmarks
commit7dac6e961a6b45cc42b3412974bfe7de007ab591 authorBryan O'Sullivan <bos@serpentine.com> dateTue 19 Mar 2013, 22:28 (14 years ago) parent3700f70
6 files changed+61−19
Data/Text/Encoding/Error.hs+5 benchmarks/haskell/Benchmarks.hs+2−1 benchmarks/haskell/Benchmarks/Builder.hs+31−8 benchmarks/haskell/Benchmarks/DecodeUtf8.hs+1−1 benchmarks/haskell/Benchmarks/Pure.hs+14−8 benchmarks/text-benchmarks.cabal+8−1
Data/Text/Encoding/Error.hs+5
@@ -35,6 +35,7 @@ module Data.Text.Encoding.Error
3535 , replace
3636 ) where
3737
38+import Control.DeepSeq (NFData (..))
3839#if __GLASGOW_HASKELL__ >= 610
3940import Control.Exception (Exception, throw)
4041#else
@@ -94,6 +95,10 @@ instance Show UnicodeException where
9495
9596instance Exception UnicodeException
9697
98+instance NFData UnicodeException where
99+ rnf (DecodeError desc w) = rnf desc `seq` rnf w `seq` ()
100+ rnf (EncodeError desc c) = rnf desc `seq` rnf c `seq` ()
101+
97102-- | Throw a 'UnicodeException' if decoding fails.
98103strictDecode :: OnDecodeError
99104strictDecode desc c = throw (DecodeError desc c)
benchmarks/haskell/Benchmarks.hs+2−1
@@ -49,7 +49,8 @@ benchmarks = do
4949 , Equality.benchmark (tf "japanese.txt")
5050 , FileRead.benchmark (tf "russian.txt")
5151 , FoldLines.benchmark (tf "russian.txt")
52− , Pure.benchmark (tf "japanese.txt")
52+ , Pure.benchmark "tiny "(tf "tiny.txt")
53+ , Pure.benchmark "japanese" (tf "japanese.txt")
5354 , ReadNumbers.benchmark (tf "numbers.txt")
5455 , Replace.benchmark (tf "russian.txt") "принимая" "своем"
5556 , Search.benchmark (tf "russian.txt") "принимая"
benchmarks/haskell/Benchmarks/Builder.hs+31−8
@@ -20,18 +20,41 @@ 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
24+import Data.Int (Int64)
2325
2426benchmark :: IO Benchmark
2527benchmark = 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
28+ [ bgroup "Comparison"
29+ [ bench "LazyText" $ nf
30+ (LT.length . LTB.toLazyText . mconcat . map LTB.fromText) texts
31+ , bench "Binary" $ nf
32+ (LB.length . B.toLazyByteString . mconcat . map B.fromByteString)
33+ byteStrings
34+ , bench "Blaze" $ nf
35+ (LB.length . Blaze.toLazyByteString . mconcat . map Blaze.fromString)
36+ strings
37+ ]
38+ , bgroup "Int"
39+ [ bgroup "Decimal"
40+ [ bgroup "Positive" .
41+ flip map numbers $ \n ->
42+ (bench (show (length (show n))) $ nf (LTB.toLazyText . Int.decimal) n)
43+ , bgroup "Negative" .
44+ flip map numbers $ \m ->
45+ let n = negate m in
46+ (bench (show (length (show n))) $ nf (LTB.toLazyText . Int.decimal) n)
47+ ]
48+ ]
3449 ]
50+ where
51+ numbers :: [Int64]
52+ numbers = [
53+ 6, 14, 500, 9688, 10654, 620735, 5608880, 37010612,
54+ 731223504, 5061580596, 24596952933, 711732309084, 2845910093839,
55+ 54601756118340, 735159434806159, 3619097625502435, 95777227510267124,
56+ 414944309510675693, 8986407456998704019
57+ ]
3558
3659texts :: [T.Text]
3760texts = take 200000 $ cycle ["foo", "λx", "由の"]
benchmarks/haskell/Benchmarks/DecodeUtf8.hs+1−1
@@ -18,7 +18,7 @@ module Benchmarks.DecodeUtf8
1818 ( benchmark
1919 ) where
2020
21−import Foreign.C.Types (CInt, CSize)
21+import Foreign.C.Types
2222import Data.ByteString.Internal (ByteString(..))
2323import Foreign.Ptr (Ptr, plusPtr)
2424import Foreign.ForeignPtr (withForeignPtr)
benchmarks/haskell/Benchmarks/Pure.hs+14−8
@@ -4,7 +4,7 @@
44--
55-- * Most pure functions defined the string types
66--
7−{-# LANGUAGE BangPatterns, GADTs, MagicHash #-}
7+{-# LANGUAGE BangPatterns, CPP, GADTs, MagicHash #-}
88{-# OPTIONS_GHC -fno-warn-orphans #-}
99module Benchmarks.Pure
1010 ( benchmark
@@ -27,8 +27,8 @@ import qualified Data.Text.Lazy as TL
2727import qualified Data.Text.Lazy.Builder as TB
2828import qualified Data.Text.Lazy.Encoding as TL
2929
30−benchmark :: FilePath -> IO Benchmark
31−benchmark fp = do
30+benchmark :: String -> FilePath -> IO Benchmark
31+benchmark kind fp = do
3232 -- Evaluate stuff before actually running the benchmark, we don't want to
3333 -- count it here.
3434
@@ -100,6 +100,10 @@ benchmark fp = do
100100 , benchBSL $ nf BL.unpack bla
101101 , benchS $ nf UTF8.toString bsa
102102 ]
103+ , bgroup "decode'"
104+ [ benchT $ nf T.decodeUtf8' bsa
105+ , benchTL $ nf TL.decodeUtf8' bla
106+ ]
103107 , bgroup "drop"
104108 [ benchT $ nf (T.drop (ta_len `div` 3)) ta
105109 , benchTL $ nf (TL.drop (tla_len `div` 3)) tla
@@ -405,11 +409,11 @@ benchmark fp = do
405409 ]
406410 ]
407411 where
408− benchS = bench "String"
409− benchT = bench "Text"
410− benchTL = bench "LazyText"
411− benchBS = bench "ByteString"
412− benchBSL = bench "LazyByteString"
412+ benchS = bench ("String+" ++ kind)
413+ benchT = bench ("Text+" ++ kind)
414+ benchTL = bench ("LazyText+" ++ kind)
415+ benchBS = bench ("ByteString+" ++ kind)
416+ benchBSL = bench ("LazyByteString+" ++ kind)
413417
414418 c = 'й'
415419 p0 = (== c)
@@ -425,11 +429,13 @@ benchmark fp = do
425429 replicat n = concat . L.replicate n
426430 short = T.pack "short"
427431
432+#if !MIN_VERSION_bytestring(0,10,0)
428433instance NFData BS.ByteString
429434
430435instance NFData BL.ByteString where
431436 rnf BL.Empty = ()
432437 rnf (BL.Chunk _ ts) = rnf ts
438+#endif
433439
434440data B where
435441 B :: NFData a => a -> B
benchmarks/text-benchmarks.cabal+8−1
@@ -15,13 +15,19 @@ build-type: Simple
1515
1616cabal-version: >=1.2
1717
18+flag llvm
19+ description: use LLVM
20+ default: False
21+
1822executable text-benchmarks
1923 hs-source-dirs: haskell ..
2024 c-sources: ../cbits/cbits.c
2125 cbits/time_iconv.c
2226 main-is: Benchmarks.hs
2327 ghc-options: -Wall -O2
24− cpp-options: -DHAVE_DEEPSEQ
28+ if flag(llvm)
29+ ghc-options: -fllvm
30+ cpp-options: -DHAVE_DEEPSEQ -DINTEGER_GMP
2531 build-depends: base == 4.*,
2632 binary,
2733 blaze-builder,
@@ -33,6 +39,7 @@ executable text-benchmarks
3339 directory,
3440 filepath,
3541 ghc-prim,
42+ integer-gmp,
3643 stringsearch,
3744 utf8-string
3845