@@ -14,11 +14,13 @@ module Data.Text.Benchmarks.Stream
14import Control.DeepSeq (NFData (..))
14import Control.DeepSeq (NFData (..))
15import Criterion (Benchmark, bgroup, bench, nf)
15import Criterion (Benchmark, bgroup, bench, nf)
16import Data.Text.Fusion.Internal (Step (..), Stream (..))
16import Data.Text.Fusion.Internal (Step (..), Stream (..))
17−import qualified Data.ByteString as B
17+import qualified Data.Text.Encoding as T
18−import qualified Data.ByteString.Lazy as BL
19import qualified Data.Text.Encoding.Error as E
18import qualified Data.Text.Encoding.Error as E
20import qualified Data.Text.Encoding.Fusion as T
19import qualified Data.Text.Encoding.Fusion as T
20+import qualified Data.Text.IO as T
21+import qualified Data.Text.Lazy.Encoding as TL
21import qualified Data.Text.Lazy.Encoding.Fusion as TL
22import qualified Data.Text.Lazy.Encoding.Fusion as TL
23+import qualified Data.Text.Lazy.IO as TL
23instance NFData a => NFData (Stream a) where
25instance NFData a => NFData (Stream a) where
24 -- Currently, this implementation does not force evaluation of the size hint
26 -- Currently, this implementation does not force evaluation of the size hint
@@ -31,13 +33,41 @@ instance NFData a => NFData (Stream a) where
32benchmark :: FilePath -> IO Benchmark
34benchmark :: FilePath -> IO Benchmark
33benchmark fp = do
35benchmark fp = do
34− -- Load data
36+ -- Different formats
35− bs <- B.readFile fp
37+ t <- T.readFile fp
38+ let !utf8 = T.encodeUtf8 t
39+ !utf16le = T.encodeUtf16LE t
40+ !utf16be = T.encodeUtf16BE t
41+ !utf32le = T.encodeUtf32LE t
42+ !utf32be = T.encodeUtf32BE t
44+ -- Once again for the lazy variants
36− lbs <- BL.readFile fp
45+ tl <- TL.readFile fp
46+ let !utf8L = TL.encodeUtf8 tl
47+ !utf16leL = TL.encodeUtf16LE tl
48+ !utf16beL = TL.encodeUtf16BE tl
49+ !utf32leL = TL.encodeUtf32LE tl
50+ !utf32beL = TL.encodeUtf32BE tl
38 return $ bgroup "Stream"
52 return $ bgroup "Stream"
39 [ bgroup "streamUtf8"
53 [ bgroup "streamUtf8"
40− [ bench "Text" $ nf (T.streamUtf8 E.lenientDecode) bs
54+ [ bench "Text" $ nf (T.streamUtf8 E.lenientDecode) utf8
41− , bench "LazyText" $ nf (TL.streamUtf8 E.lenientDecode) lbs
55+ , bench "LazyText" $ nf (TL.streamUtf8 E.lenientDecode) utf8L
57+ , bgroup "streamUtf16LE"
58+ [ bench "Text" $ nf (T.streamUtf16LE E.lenientDecode) utf16le
59+ , bench "LazyText" $ nf (TL.streamUtf16LE E.lenientDecode) utf16leL
61+ , bgroup "streamUtf16BE"
62+ [ bench "Text" $ nf (T.streamUtf16BE E.lenientDecode) utf16be
63+ , bench "LazyText" $ nf (TL.streamUtf16BE E.lenientDecode) utf16beL
65+ , bgroup "streamUtf32LE"
66+ [ bench "Text" $ nf (T.streamUtf32LE E.lenientDecode) utf32le
67+ , bench "LazyText" $ nf (TL.streamUtf32LE E.lenientDecode) utf32leL
69+ , bgroup "streamUtf32BE"
70+ [ bench "Text" $ nf (T.streamUtf32BE E.lenientDecode) utf32be
71+ , bench "LazyText" $ nf (TL.streamUtf32BE E.lenientDecode) utf32beL