@@ -14,11 +14,13 @@ module Data.Text.Benchmarks.Stream
1414import Control.DeepSeq (NFData (..))
1515import Criterion (Benchmark, bgroup, bench, nf)
1616import Data.Text.Fusion.Internal (Step (..), Stream (..))
17−import qualified Data.ByteString as B
18−import qualified Data.ByteString.Lazy as BL
17+import qualified Data.Text.Encoding as T
1918import qualified Data.Text.Encoding.Error as E
2019import qualified Data.Text.Encoding.Fusion as T
20+import qualified Data.Text.IO as T
21+import qualified Data.Text.Lazy.Encoding as TL
2122import qualified Data.Text.Lazy.Encoding.Fusion as TL
23+import qualified Data.Text.Lazy.IO as TL
2224
2325instance NFData a => NFData (Stream a) where
2426 -- Currently, this implementation does not force evaluation of the size hint
@@ -31,13 +33,41 @@ instance NFData a => NFData (Stream a) where
3133
3234benchmark :: FilePath -> IO Benchmark
3335benchmark fp = do
34− -- Load data
35− bs <- B.readFile fp
36− lbs <- BL.readFile fp
36+ -- Different formats
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
43+
44+ -- Once again for the lazy variants
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
3751
3852 return $ bgroup "Stream"
3953 [ bgroup "streamUtf8"
40− [ bench "Text" $ nf (T.streamUtf8 E.lenientDecode) bs
41− , bench "LazyText" $ nf (TL.streamUtf8 E.lenientDecode) lbs
54+ [ bench "Text" $ nf (T.streamUtf8 E.lenientDecode) utf8
55+ , bench "LazyText" $ nf (TL.streamUtf8 E.lenientDecode) utf8L
56+ ]
57+ , bgroup "streamUtf16LE"
58+ [ bench "Text" $ nf (T.streamUtf16LE E.lenientDecode) utf16le
59+ , bench "LazyText" $ nf (TL.streamUtf16LE E.lenientDecode) utf16leL
60+ ]
61+ , bgroup "streamUtf16BE"
62+ [ bench "Text" $ nf (T.streamUtf16BE E.lenientDecode) utf16be
63+ , bench "LazyText" $ nf (TL.streamUtf16BE E.lenientDecode) utf16beL
64+ ]
65+ , bgroup "streamUtf32LE"
66+ [ bench "Text" $ nf (T.streamUtf32LE E.lenientDecode) utf32le
67+ , bench "LazyText" $ nf (TL.streamUtf32LE E.lenientDecode) utf32leL
68+ ]
69+ , bgroup "streamUtf32BE"
70+ [ bench "Text" $ nf (T.streamUtf32BE E.lenientDecode) utf32be
71+ , bench "LazyText" $ nf (TL.streamUtf32BE E.lenientDecode) utf32beL
4272 ]
4373 ]