Commit 86e986d1 authored by Bodigrim's avatar Bodigrim Committed by Xia Li-yao
Browse files

Group benchmarks in a proper way

parent e4f37ecc
......@@ -39,25 +39,31 @@ main = do
defaultMain
[ Builder.benchmark
, Concat.benchmark
, env (DecodeUtf8.initEnv (tf "libya-chinese.html")) (DecodeUtf8.benchmark "html")
, env (DecodeUtf8.initEnv (tf "yiwiki.xml")) (DecodeUtf8.benchmark "xml")
, env (DecodeUtf8.initEnv (tf "ascii.txt")) (DecodeUtf8.benchmark "ascii")
, env (DecodeUtf8.initEnv (tf "russian.txt")) (DecodeUtf8.benchmark "russian")
, env (DecodeUtf8.initEnv (tf "japanese.txt")) (DecodeUtf8.benchmark "japanese")
, env (DecodeUtf8.initEnv (tf "ascii.txt")) (DecodeUtf8.benchmarkASCII)
, EncodeUtf8.benchmark "non-ASCII" "επανάληψη 竺法蘭共譯"
, EncodeUtf8.benchmark "ASCII" "lorem ipsum"
, bgroup "DecodeUtf8"
[ env (DecodeUtf8.initEnv (tf "libya-chinese.html")) (DecodeUtf8.benchmark "html")
, env (DecodeUtf8.initEnv (tf "yiwiki.xml")) (DecodeUtf8.benchmark "xml")
, env (DecodeUtf8.initEnv (tf "ascii.txt")) (DecodeUtf8.benchmark "ascii")
, env (DecodeUtf8.initEnv (tf "russian.txt")) (DecodeUtf8.benchmark "russian")
, env (DecodeUtf8.initEnv (tf "japanese.txt")) (DecodeUtf8.benchmark "japanese")
, env (DecodeUtf8.initEnv (tf "ascii.txt")) (DecodeUtf8.benchmarkASCII)
]
, bgroup "EncodeUtf8"
[ EncodeUtf8.benchmark "non-ASCII" "επανάληψη 竺法蘭共譯"
, EncodeUtf8.benchmark "ASCII" "lorem ipsum"
]
, env (Equality.initEnv (tf "japanese.txt")) Equality.benchmark
, FileRead.benchmark (tf "russian.txt")
, FoldLines.benchmark (tf "russian.txt")
, env Mul.initEnv Mul.benchmark
, Multilang.benchmark
, env (Pure.initEnv (tf "tiny.txt")) (Pure.benchmark "tiny")
, env (Pure.initEnv (tf "ascii-small.txt")) (Pure.benchmark "ascii-small")
, env (Pure.initEnv (tf "ascii.txt")) (Pure.benchmark "ascii")
, env (Pure.initEnv (tf "english.txt")) (Pure.benchmark "english")
, env (Pure.initEnv (tf "russian-small.txt")) (Pure.benchmark "russian")
, env (Pure.initEnv (tf "japanese.txt")) (Pure.benchmark "japanese")
, bgroup "Pure"
[ env (Pure.initEnv (tf "tiny.txt")) (Pure.benchmark "tiny")
, env (Pure.initEnv (tf "ascii-small.txt")) (Pure.benchmark "ascii-small")
, env (Pure.initEnv (tf "ascii.txt")) (Pure.benchmark "ascii")
, env (Pure.initEnv (tf "english.txt")) (Pure.benchmark "english")
, env (Pure.initEnv (tf "russian-small.txt")) (Pure.benchmark "russian")
, env (Pure.initEnv (tf "japanese.txt")) (Pure.benchmark "japanese")
]
, env (ReadNumbers.initEnv (tf "numbers.txt")) ReadNumbers.benchmark
, env (Replace.initEnv (tf "russian.txt")) (Replace.benchmark "принимая" "своем")
, env (Search.initEnv (tf "russian.txt")) (Search.benchmark "принимая")
......
......@@ -22,8 +22,7 @@ module Benchmarks.DecodeUtf8
) where
import Data.ByteString.Lazy.Internal (ByteString(..))
import qualified Test.Tasty.Bench as C
import Test.Tasty.Bench (Benchmark, bgroup, nf)
import Test.Tasty.Bench
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.Text as T
......@@ -41,14 +40,13 @@ initEnv fp = do
benchmark :: String -> Env -> Benchmark
benchmark kind ~(bs, lbs) =
let bench name = C.bench (name ++ "+" ++ kind)
decodeStream (Chunk b0 bs0) = case T.streamDecodeUtf8 b0 of
let decodeStream (Chunk b0 bs0) = case T.streamDecodeUtf8 b0 of
T.Some t0 _ f0 -> t0 : go f0 bs0
where go f (Chunk b bs1) = case f b of
T.Some t1 _ f1 -> t1 : go f1 bs1
go _ _ = []
decodeStream _ = []
in bgroup "DecodeUtf8"
in bgroup kind
[ bench "Strict" $ nf T.decodeUtf8 bs
, bench "Stream" $ nf decodeStream lbs
, bench "StrictLength" $ nf (T.length . T.decodeUtf8) bs
......@@ -60,11 +58,11 @@ benchmark kind ~(bs, lbs) =
benchmarkASCII :: Env -> Benchmark
benchmarkASCII ~(bs, lbs) =
bgroup "DecodeASCII"
[ C.bench "strict decodeUtf8" $ nf T.decodeUtf8 bs
, C.bench "strict decodeLatin1" $ nf T.decodeLatin1 bs
, C.bench "strict decodeASCII" $ nf T.decodeASCII bs
, C.bench "lazy decodeUtf8" $ nf TL.decodeUtf8 lbs
, C.bench "lazy decodeLatin1" $ nf TL.decodeLatin1 lbs
, C.bench "lazy decodeASCII" $ nf TL.decodeASCII lbs
bgroup "ascii"
[ bench "strict decodeUtf8" $ nf T.decodeUtf8 bs
, bench "strict decodeLatin1" $ nf T.decodeLatin1 bs
, bench "strict decodeASCII" $ nf T.decodeASCII bs
, bench "lazy decodeUtf8" $ nf TL.decodeUtf8 lbs
, bench "lazy decodeLatin1" $ nf TL.decodeLatin1 lbs
, bench "lazy decodeASCII" $ nf TL.decodeASCII lbs
]
......@@ -20,9 +20,9 @@ import qualified Data.Text.Lazy.Encoding as TL
benchmark :: String -> String -> Benchmark
benchmark name string =
bgroup "EncodeUtf8"
[ bench ("Text (" ++ name ++ ")") $ whnf (B.length . T.encodeUtf8) text
, bench ("LazyText (" ++ name ++ ")") $ whnf (BL.length . TL.encodeUtf8) lazyText
bgroup name
[ bench "Text" $ whnf (B.length . T.encodeUtf8) text
, bench "LazyText" $ whnf (BL.length . TL.encodeUtf8) lazyText
]
where
-- The string in different formats
......
......@@ -74,7 +74,7 @@ initEnv fp = do
benchmark :: String -> Env -> Benchmark
benchmark kind ~Env{..} =
bgroup "Pure"
bgroup kind
[ bgroup "append"
[ benchT $ nf (T.append tb) ta
, benchTL $ nf (TL.append tlb) tla
......@@ -279,17 +279,17 @@ benchmark kind ~Env{..} =
]
]
, bgroup "Builder"
[ bench ("mappend char+" ++ kind) $
[ bench "mappend char" $
nf (TL.length . TB.toLazyText . mappendNChar 'a') 10000
, bench ("mappend 8 char+" ++ kind) $
, bench "mappend 8 char" $
nf (TL.length . TB.toLazyText . mappend8Char) 'a'
, bench ("mappend text+" ++ kind) $
, bench "mappend text" $
nf (TL.length . TB.toLazyText . mappendNText short) 10000
]
]
where
benchT = bench ("Text+" ++ kind)
benchTL = bench ("LazyText+" ++ kind)
benchT = bench "Text"
benchTL = bench "LazyText"
c = 'й'
p0 = (== c)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment