Bryan O'Sullivan avatar Bryan O'Sullivan committed 2bbce01

Allow decoding of multiple files when benchmarking

Comments (0)

Files changed (2)

tests/benchmarks/src/Data/Text/Benchmarks.hs

     -- Traditional benchmarks
     bs <- sequence
         [ Builder.benchmark
-        , DecodeUtf8.benchmark (tf "russian.txt")
+        , DecodeUtf8.benchmark "xml" (tf "yiwiki.xml")
+        , DecodeUtf8.benchmark "ascii" (tf "ascii.txt")
+        , DecodeUtf8.benchmark "russian" (tf "russian.txt")
+        , DecodeUtf8.benchmark "japanese" (tf "japanese.txt")
         , EncodeUtf8.benchmark "επανάληψη 竺法蘭共譯"
         , Equality.benchmark (tf "japanese.txt")
         , FileRead.benchmark (tf "russian.txt")

tests/benchmarks/src/Data/Text/Benchmarks/DecodeUtf8.hs

 import Foreign.Ptr (Ptr, plusPtr)
 import Foreign.ForeignPtr (withForeignPtr)
 import Data.Word (Word8)
-import Criterion (Benchmark, bgroup, bench, nf)
+import qualified Criterion as C
+import Criterion (Benchmark, bgroup, nf)
 import qualified Codec.Binary.UTF8.Generic as U8
 import qualified Data.ByteString as B
 import qualified Data.ByteString.Lazy as BL
 import qualified Data.Text.Lazy as TL
 import qualified Data.Text.Lazy.Encoding as TL
 
-benchmark :: FilePath -> IO Benchmark
-benchmark fp = do
+benchmark :: String -> FilePath -> IO Benchmark
+benchmark kind fp = do
     bs  <- B.readFile fp
     lbs <- BL.readFile fp
+    let bench name = C.bench (name ++ "+" ++ kind)
     return $ bgroup "DecodeUtf8"
         [ bench "Strict" $ nf T.decodeUtf8 bs
         , bench "IConv" $ iconv bs
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.