diff --git a/benchmarks/haskell/Benchmarks.hs b/benchmarks/haskell/Benchmarks.hs index 55707964..eb398062 100644 --- a/benchmarks/haskell/Benchmarks.hs +++ b/benchmarks/haskell/Benchmarks.hs @@ -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 "принимая") diff --git a/benchmarks/haskell/Benchmarks/DecodeUtf8.hs b/benchmarks/haskell/Benchmarks/DecodeUtf8.hs index 0558d3b4..e9e18eb8 100644 --- a/benchmarks/haskell/Benchmarks/DecodeUtf8.hs +++ b/benchmarks/haskell/Benchmarks/DecodeUtf8.hs @@ -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 ] diff --git a/benchmarks/haskell/Benchmarks/EncodeUtf8.hs b/benchmarks/haskell/Benchmarks/EncodeUtf8.hs index ff9a4d8e..5dd09ca0 100644 --- a/benchmarks/haskell/Benchmarks/EncodeUtf8.hs +++ b/benchmarks/haskell/Benchmarks/EncodeUtf8.hs @@ -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 diff --git a/benchmarks/haskell/Benchmarks/Pure.hs b/benchmarks/haskell/Benchmarks/Pure.hs index 39e2439c..a4dc4fbb 100644 --- a/benchmarks/haskell/Benchmarks/Pure.hs +++ b/benchmarks/haskell/Benchmarks/Pure.hs @@ -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)