on master help sign in
Backport integer builder benchmarks
7dac6e9Bryan O'Sullivan
Data/Text/Encoding/Error.hs+5
@@ -35,6 +35,7 @@ module Data.Text.Encoding.Error
35 , replace
35 , replace
36 ) where
36 ) where
37
37
38+import Control.DeepSeq (NFData (..))
38#if __GLASGOW_HASKELL__ >= 610
39#if __GLASGOW_HASKELL__ >= 610
39import Control.Exception (Exception, throw)
40import Control.Exception (Exception, throw)
40#else
41#else
@@ -94,6 +95,10 @@ instance Show UnicodeException where
94
95
95instance Exception UnicodeException
96instance Exception UnicodeException
96
97
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+
97-- | Throw a 'UnicodeException' if decoding fails.
102-- | Throw a 'UnicodeException' if decoding fails.
98strictDecode :: OnDecodeError
103strictDecode :: OnDecodeError
99strictDecode desc c = throw (DecodeError desc c)
104strictDecode desc c = throw (DecodeError desc c)
benchmarks/haskell/Benchmarks.hs+2−1
@@ -49,7 +49,8 @@ benchmarks = do
49 , Equality.benchmark (tf "japanese.txt")
49 , Equality.benchmark (tf "japanese.txt")
50 , FileRead.benchmark (tf "russian.txt")
50 , FileRead.benchmark (tf "russian.txt")
51 , FoldLines.benchmark (tf "russian.txt")
51 , 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")
53 , ReadNumbers.benchmark (tf "numbers.txt")
54 , ReadNumbers.benchmark (tf "numbers.txt")
54 , Replace.benchmark (tf "russian.txt") "принимая" "своем"
55 , Replace.benchmark (tf "russian.txt") "принимая" "своем"
55 , Search.benchmark (tf "russian.txt") "принимая"
56 , Search.benchmark (tf "russian.txt") "принимая"
benchmarks/haskell/Benchmarks/Builder.hs+31−8
@@ -20,18 +20,41 @@ 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
24+import Data.Int (Int64)
23
25
24benchmark :: IO Benchmark
26benchmark :: IO Benchmark
25benchmark = return $ bgroup "Builder"
27benchmark = return $ bgroup "Builder"
28+ [ bgroup "Comparison"
26− [ bench "LazyText" $ nf
29+ [ bench "LazyText" $ nf
27− (LT.length . LTB.toLazyText . mconcat . map LTB.fromText) texts
30+ (LT.length . LTB.toLazyText . mconcat . map LTB.fromText) texts
28− , bench "Binary" $ nf
31+ , bench "Binary" $ nf
29− (LB.length . B.toLazyByteString . mconcat . map B.fromByteString)
32+ (LB.length . B.toLazyByteString . mconcat . map B.fromByteString)
30− byteStrings
33+ byteStrings
31− , bench "Blaze" $ nf
34+ , bench "Blaze" $ nf
32− (LB.length . Blaze.toLazyByteString . mconcat . map Blaze.fromString)
35+ (LB.length . Blaze.toLazyByteString . mconcat . map Blaze.fromString)
33− strings
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+ ]
34 ]
49 ]
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+ ]
35
58
36texts :: [T.Text]
59texts :: [T.Text]
37texts = take 200000 $ cycle ["foo", "λx", "由の"]
60texts = take 200000 $ cycle ["foo", "λx", "由の"]
benchmarks/haskell/Benchmarks/DecodeUtf8.hs+1−1
@@ -18,7 +18,7 @@ module Benchmarks.DecodeUtf8
18 ( benchmark
18 ( benchmark
19 ) where
19 ) where
20
20
21−import Foreign.C.Types (CInt, CSize)
21+import Foreign.C.Types
22import Data.ByteString.Internal (ByteString(..))
22import Data.ByteString.Internal (ByteString(..))
23import Foreign.Ptr (Ptr, plusPtr)
23import Foreign.Ptr (Ptr, plusPtr)
24import Foreign.ForeignPtr (withForeignPtr)
24import Foreign.ForeignPtr (withForeignPtr)
benchmarks/haskell/Benchmarks/Pure.hs+14−8
@@ -4,7 +4,7 @@
4--
4--
5-- * Most pure functions defined the string types
5-- * Most pure functions defined the string types
6--
6--
7−{-# LANGUAGE BangPatterns, GADTs, MagicHash #-}
7+{-# LANGUAGE BangPatterns, CPP, GADTs, MagicHash #-}
8{-# OPTIONS_GHC -fno-warn-orphans #-}
8{-# OPTIONS_GHC -fno-warn-orphans #-}
9module Benchmarks.Pure
9module Benchmarks.Pure
10 ( benchmark
10 ( benchmark
@@ -27,8 +27,8 @@ import qualified Data.Text.Lazy as TL
27import qualified Data.Text.Lazy.Builder as TB
27import qualified Data.Text.Lazy.Builder as TB
28import qualified Data.Text.Lazy.Encoding as TL
28import qualified Data.Text.Lazy.Encoding as TL
29
29
30−benchmark :: FilePath -> IO Benchmark
30+benchmark :: String -> FilePath -> IO Benchmark
31−benchmark fp = do
31+benchmark kind fp = do
32 -- Evaluate stuff before actually running the benchmark, we don't want to
32 -- Evaluate stuff before actually running the benchmark, we don't want to
33 -- count it here.
33 -- count it here.
34
34
@@ -100,6 +100,10 @@ benchmark fp = do
100 , benchBSL $ nf BL.unpack bla
100 , benchBSL $ nf BL.unpack bla
101 , benchS $ nf UTF8.toString bsa
101 , benchS $ nf UTF8.toString bsa
102 ]
102 ]
103+ , bgroup "decode'"
104+ [ benchT $ nf T.decodeUtf8' bsa
105+ , benchTL $ nf TL.decodeUtf8' bla
106+ ]
103 , bgroup "drop"
107 , bgroup "drop"
104 [ benchT $ nf (T.drop (ta_len `div` 3)) ta
108 [ benchT $ nf (T.drop (ta_len `div` 3)) ta
105 , benchTL $ nf (TL.drop (tla_len `div` 3)) tla
109 , benchTL $ nf (TL.drop (tla_len `div` 3)) tla
@@ -405,11 +409,11 @@ benchmark fp = do
405 ]
409 ]
406 ]
410 ]
407 where
411 where
408− benchS = bench "String"
412+ benchS = bench ("String+" ++ kind)
409− benchT = bench "Text"
413+ benchT = bench ("Text+" ++ kind)
410− benchTL = bench "LazyText"
414+ benchTL = bench ("LazyText+" ++ kind)
411− benchBS = bench "ByteString"
415+ benchBS = bench ("ByteString+" ++ kind)
412− benchBSL = bench "LazyByteString"
416+ benchBSL = bench ("LazyByteString+" ++ kind)
413
417
414 c = 'й'
418 c = 'й'
415 p0 = (== c)
419 p0 = (== c)
@@ -425,11 +429,13 @@ benchmark fp = do
425 replicat n = concat . L.replicate n
429 replicat n = concat . L.replicate n
426 short = T.pack "short"
430 short = T.pack "short"
427
431
432+#if !MIN_VERSION_bytestring(0,10,0)
428instance NFData BS.ByteString
433instance NFData BS.ByteString
429
434
430instance NFData BL.ByteString where
435instance NFData BL.ByteString where
431 rnf BL.Empty = ()
436 rnf BL.Empty = ()
432 rnf (BL.Chunk _ ts) = rnf ts
437 rnf (BL.Chunk _ ts) = rnf ts
438+#endif
433
439
434data B where
440data B where
435 B :: NFData a => a -> B
441 B :: NFData a => a -> B
benchmarks/text-benchmarks.cabal+8−1
@@ -15,13 +15,19 @@ build-type: Simple
15
15
16cabal-version: >=1.2
16cabal-version: >=1.2
17
17
18+flag llvm
19+ description: use LLVM
20+ default: False
21+
18executable text-benchmarks
22executable text-benchmarks
19 hs-source-dirs: haskell ..
23 hs-source-dirs: haskell ..
20 c-sources: ../cbits/cbits.c
24 c-sources: ../cbits/cbits.c
21 cbits/time_iconv.c
25 cbits/time_iconv.c
22 main-is: Benchmarks.hs
26 main-is: Benchmarks.hs
23 ghc-options: -Wall -O2
27 ghc-options: -Wall -O2
28+ if flag(llvm)
29+ ghc-options: -fllvm
24− cpp-options: -DHAVE_DEEPSEQ
30+ cpp-options: -DHAVE_DEEPSEQ -DINTEGER_GMP
25 build-depends: base == 4.*,
31 build-depends: base == 4.*,
26 binary,
32 binary,
27 blaze-builder,
33 blaze-builder,
@@ -33,6 +39,7 @@ executable text-benchmarks
33 directory,
39 directory,
34 filepath,
40 filepath,
35 ghc-prim,
41 ghc-prim,
42+ integer-gmp,
36 stringsearch,
43 stringsearch,
37 utf8-string
44 utf8-string
38
45