on master help sign in
Add benchmarks for decodeUtf8'

Also make it possible to run the Pure benchmark with a very short input string. This lets us test the constant overheads in functions, such as the one added by unsafePerformIO in decodeUtf8.

commit7fd8f1852617bfc364f7c36cc6c194e323704e15 authorJohan Tibell <johan.tibell@gmail.com> dateSun 24 Feb 2013, 17:54 (14 years ago) parentfb39275
3 files changed+18−8
Data/Text/Encoding/Error.hs+5 benchmarks/haskell/Benchmarks.hs+2−1 benchmarks/haskell/Benchmarks/Pure.hs+11−7
Data/Text/Encoding/Error.hs+5
@@ -38,6 +38,7 @@ module Data.Text.Encoding.Error
3838 , replace
3939 ) where
4040
41+import Control.DeepSeq (NFData (..))
4142#if __GLASGOW_HASKELL__ >= 610
4243import Control.Exception (Exception, throw)
4344#else
@@ -97,6 +98,10 @@ instance Show UnicodeException where
9798
9899instance Exception UnicodeException
99100
101+instance NFData UnicodeException where
102+ rnf (DecodeError desc w) = rnf desc `seq` rnf w `seq` ()
103+ rnf (EncodeError desc c) = rnf desc `seq` rnf c `seq` ()
104+
100105-- | Throw a 'UnicodeException' if decoding fails.
101106strictDecode :: OnDecodeError
102107strictDecode 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/Pure.hs+11−7
@@ -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)