tibbe avatar tibbe committed d2517d0

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.

Comments (0)

Files changed (3)

Data/Text/Encoding/Error.hs

     , replace
     ) where
 
+import Control.DeepSeq (NFData (..))
 #if __GLASGOW_HASKELL__ >= 610
 import Control.Exception (Exception, throw)
 #else
 
 instance Exception UnicodeException
 
+instance NFData UnicodeException where
+    rnf (DecodeError desc w) = rnf desc `seq` rnf w `seq` ()
+    rnf (EncodeError desc c) = rnf desc `seq` rnf c `seq` ()
+
 -- | Throw a 'UnicodeException' if decoding fails.
 strictDecode :: OnDecodeError
 strictDecode desc c = throw (DecodeError desc c)

benchmarks/haskell/Benchmarks.hs

         , Equality.benchmark (tf "japanese.txt")
         , FileRead.benchmark (tf "russian.txt")
         , FoldLines.benchmark (tf "russian.txt")
-        , Pure.benchmark (tf "japanese.txt")
+        , Pure.benchmark "tiny "(tf "tiny.txt")
+        , Pure.benchmark "japanese" (tf "japanese.txt")
         , ReadNumbers.benchmark (tf "numbers.txt")
         , Replace.benchmark (tf "russian.txt") "принимая" "своем"
         , Search.benchmark (tf "russian.txt") "принимая"

benchmarks/haskell/Benchmarks/Pure.hs

 import qualified Data.Text.Lazy.Builder as TB
 import qualified Data.Text.Lazy.Encoding as TL
 
-benchmark :: FilePath -> IO Benchmark
-benchmark fp = do
+benchmark :: String -> FilePath -> IO Benchmark
+benchmark kind fp = do
     -- Evaluate stuff before actually running the benchmark, we don't want to
     -- count it here.
 
             , benchBSL $ nf BL.unpack bla
             , benchS   $ nf UTF8.toString bsa
             ]
+        , bgroup "decode'"
+            [ benchT   $ nf T.decodeUtf8' bsa
+            , benchTL  $ nf TL.decodeUtf8' bla
+            ]
         , bgroup "drop"
             [ benchT   $ nf (T.drop (ta_len `div` 3)) ta
             , benchTL  $ nf (TL.drop (tla_len `div` 3)) tla
             ]
         ]
   where
-    benchS   = bench "String"
-    benchT   = bench "Text"
-    benchTL  = bench "LazyText"
-    benchBS  = bench "ByteString"
-    benchBSL = bench "LazyByteString"
+    benchS   = bench ("String+" ++ kind)
+    benchT   = bench ("Text+" ++ kind)
+    benchTL  = bench ("LazyText+" ++ kind)
+    benchBS  = bench ("ByteString+" ++ kind)
+    benchBSL = bench ("LazyByteString+" ++ kind)
 
     c  = 'й'
     p0 = (== c)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.