on master help sign in
Add benchmarks for decodeUtf8'
7fd8f18Johan Tibell
Data/Text/Encoding/Error.hs+5
@@ -38,6 +38,7 @@ module Data.Text.Encoding.Error
38 , replace
38 , replace
39 ) where
39 ) where
40
40
41+import Control.DeepSeq (NFData (..))
41#if __GLASGOW_HASKELL__ >= 610
42#if __GLASGOW_HASKELL__ >= 610
42import Control.Exception (Exception, throw)
43import Control.Exception (Exception, throw)
43#else
44#else
@@ -97,6 +98,10 @@ instance Show UnicodeException where
97
98
98instance Exception UnicodeException
99instance Exception UnicodeException
99
100
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+
100-- | Throw a 'UnicodeException' if decoding fails.
105-- | Throw a 'UnicodeException' if decoding fails.
101strictDecode :: OnDecodeError
106strictDecode :: OnDecodeError
102strictDecode desc c = throw (DecodeError desc c)
107strictDecode 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/Pure.hs+11−7
@@ -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)