Skip to content
Browse files

Merge 1b33e08 into 3845ffd

  • Loading branch information...
2 parents 3845ffd + 1b33e08 commit 1b6d5ff09f14cd7eef2cbf20e4c519a70e46f051 GitHub Merge Button committed
View
2 tests/benchmarks/src/Data/Text/Benchmarks.hs
@@ -19,6 +19,7 @@ import qualified Data.Text.Benchmarks.Pure as Pure
import qualified Data.Text.Benchmarks.ReadNumbers as ReadNumbers
import qualified Data.Text.Benchmarks.Replace as Replace
import qualified Data.Text.Benchmarks.Search as Search
+import qualified Data.Text.Benchmarks.Stream as Stream
import qualified Data.Text.Benchmarks.WordFrequencies as WordFrequencies
import qualified Data.Text.Benchmarks.Programs.BigTable as Programs.BigTable
@@ -52,6 +53,7 @@ benchmarks = do
, ReadNumbers.benchmark (tf "numbers.txt")
, Replace.benchmark (tf "russian.txt") "принимая" "своем"
, Search.benchmark (tf "russian.txt") "принимая"
+ , Stream.benchmark (tf "russian.txt")
, WordFrequencies.benchmark (tf "russian.txt")
]
View
13 tests/benchmarks/src/Data/Text/Benchmarks/Programs/Sort.hs
@@ -21,15 +21,17 @@ import Criterion (Benchmark, bgroup, bench)
import Data.Monoid (mconcat)
import System.IO (Handle, hPutStr)
import qualified Data.ByteString as B
+import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Lazy.Char8 as BLC
-import qualified Data.ByteString.Char8 as BC
import qualified Data.List as L
import qualified Data.Text as T
+import qualified Data.Text.Encoding as T
import qualified Data.Text.IO as T
import qualified Data.Text.Lazy as TL
-import qualified Data.Text.Lazy.IO as TL
import qualified Data.Text.Lazy.Builder as TLB
+import qualified Data.Text.Lazy.Encoding as TL
+import qualified Data.Text.Lazy.IO as TL
benchmark :: FilePath -> Handle -> IO Benchmark
benchmark i o = return $ bgroup "Sort"
@@ -38,7 +40,12 @@ benchmark i o = return $ bgroup "Sort"
, bench "LazyByteString" $ BL.readFile i >>= BL.hPutStr o . lazyByteString
, bench "Text" $ T.readFile i >>= T.hPutStr o . text
, bench "LazyText" $ TL.readFile i >>= TL.hPutStr o . lazyText
- , bench "TextBuilder" $ T.readFile i >>= TL.hPutStr o . textBuilder
+ , bench "TextByteString" $ B.readFile i >>=
+ B.hPutStr o . T.encodeUtf8 . text . T.decodeUtf8
+ , bench "LazyTextByteString" $ BL.readFile i >>=
+ BL.hPutStr o . TL.encodeUtf8 . lazyText . TL.decodeUtf8
+ , bench "TextBuilder" $ B.readFile i >>=
+ BL.hPutStr o . TL.encodeUtf8 . textBuilder . T.decodeUtf8
]
string :: String -> String
View
4 tests/benchmarks/src/Data/Text/Benchmarks/Programs/StripTags.hs
@@ -22,12 +22,14 @@ import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
+import qualified Data.Text.IO as T
benchmark :: FilePath -> Handle -> IO Benchmark
benchmark i o = return $ bgroup "StripTags"
[ bench "String" $ readFile i >>= hPutStr o . string
, bench "ByteString" $ B.readFile i >>= B.hPutStr o . byteString
- , bench "Text" $
+ , bench "Text" $ T.readFile i >>= T.hPutStr o . text
+ , bench "TextByteString" $
B.readFile i >>= B.hPutStr o . T.encodeUtf8 . text . T.decodeUtf8
]
View
6 tests/benchmarks/src/Data/Text/Benchmarks/Programs/Throughput.hs
@@ -22,7 +22,9 @@ import Criterion (Benchmark, bgroup, bench)
import System.IO (Handle, hPutStr)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
+import qualified Data.Text.Encoding as T
import qualified Data.Text.IO as T
+import qualified Data.Text.Lazy.Encoding as TL
import qualified Data.Text.Lazy.IO as TL
benchmark :: FilePath -> Handle -> IO Benchmark
@@ -32,4 +34,8 @@ benchmark fp sink = return $ bgroup "Throughput"
, bench "LazyByteString" $ BL.readFile fp >>= BL.hPutStr sink
, bench "Text" $ T.readFile fp >>= T.hPutStr sink
, bench "LazyText" $ TL.readFile fp >>= TL.hPutStr sink
+ , bench "TextByteString" $
+ B.readFile fp >>= B.hPutStr sink . T.encodeUtf8 . T.decodeUtf8
+ , bench "LazyTextByteString" $
+ BL.readFile fp >>= BL.hPutStr sink . TL.encodeUtf8 . TL.decodeUtf8
]
View
94 tests/benchmarks/src/Data/Text/Benchmarks/Stream.hs
@@ -0,0 +1,94 @@
+-- | This module contains a number of benchmarks for the different streaming
+-- functions
+--
+-- Tested in this benchmark:
+--
+-- * Most streaming functions
+--
+{-# LANGUAGE BangPatterns #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+module Data.Text.Benchmarks.Stream
+ ( benchmark
+ ) where
+
+import Control.DeepSeq (NFData (..))
+import Criterion (Benchmark, bgroup, bench, nf)
+import Data.Text.Fusion.Internal (Step (..), Stream (..))
+import qualified Data.Text.Encoding as T
+import qualified Data.Text.Encoding.Error as E
+import qualified Data.Text.Encoding.Fusion as T
+import qualified Data.Text.Encoding.Fusion.Common as F
+import qualified Data.Text.Fusion as T
+import qualified Data.Text.IO as T
+import qualified Data.Text.Lazy.Encoding as TL
+import qualified Data.Text.Lazy.Encoding.Fusion as TL
+import qualified Data.Text.Lazy.Fusion as TL
+import qualified Data.Text.Lazy.IO as TL
+
+instance NFData a => NFData (Stream a) where
+ -- Currently, this implementation does not force evaluation of the size hint
+ rnf (Stream next s0 _) = go s0
+ where
+ go !s = case next s of
+ Done -> ()
+ Skip s' -> go s'
+ Yield x s' -> rnf x `seq` go s'
+
+benchmark :: FilePath -> IO Benchmark
+benchmark fp = do
+ -- Different formats
+ t <- T.readFile fp
+ let !utf8 = T.encodeUtf8 t
+ !utf16le = T.encodeUtf16LE t
+ !utf16be = T.encodeUtf16BE t
+ !utf32le = T.encodeUtf32LE t
+ !utf32be = T.encodeUtf32BE t
+
+ -- Once again for the lazy variants
+ tl <- TL.readFile fp
+ let !utf8L = TL.encodeUtf8 tl
+ !utf16leL = TL.encodeUtf16LE tl
+ !utf16beL = TL.encodeUtf16BE tl
+ !utf32leL = TL.encodeUtf32LE tl
+ !utf32beL = TL.encodeUtf32BE tl
+
+ -- For the functions which operate on streams
+ let !s = T.stream t
+
+ return $ bgroup "Stream"
+
+ -- Fusion
+ [ bgroup "stream" $
+ [ bench "Text" $ nf T.stream t
+ , bench "LazyText" $ nf TL.stream tl
+ ]
+
+ -- Encoding.Fusion
+ , bgroup "streamUtf8"
+ [ bench "Text" $ nf (T.streamUtf8 E.lenientDecode) utf8
+ , bench "LazyText" $ nf (TL.streamUtf8 E.lenientDecode) utf8L
+ ]
+ , bgroup "streamUtf16LE"
+ [ bench "Text" $ nf (T.streamUtf16LE E.lenientDecode) utf16le
+ , bench "LazyText" $ nf (TL.streamUtf16LE E.lenientDecode) utf16leL
+ ]
+ , bgroup "streamUtf16BE"
+ [ bench "Text" $ nf (T.streamUtf16BE E.lenientDecode) utf16be
+ , bench "LazyText" $ nf (TL.streamUtf16BE E.lenientDecode) utf16beL
+ ]
+ , bgroup "streamUtf32LE"
+ [ bench "Text" $ nf (T.streamUtf32LE E.lenientDecode) utf32le
+ , bench "LazyText" $ nf (TL.streamUtf32LE E.lenientDecode) utf32leL
+ ]
+ , bgroup "streamUtf32BE"
+ [ bench "Text" $ nf (T.streamUtf32BE E.lenientDecode) utf32be
+ , bench "LazyText" $ nf (TL.streamUtf32BE E.lenientDecode) utf32beL
+ ]
+
+ -- Encoding.Fusion.Common
+ , bench "restreamUtf8" $ nf F.restreamUtf8 s
+ , bench "restreamUtf16LE" $ nf F.restreamUtf16LE s
+ , bench "restreamUtf16BE" $ nf F.restreamUtf16BE s
+ , bench "restreamUtf32LE" $ nf F.restreamUtf32LE s
+ , bench "restreamUtf32BE" $ nf F.restreamUtf32BE s
+ ]

0 comments on commit 1b6d5ff

Please sign in to comment.
Something went wrong with that request. Please try again.