on master help sign in
Merge 1b33e0812bf036b250c094d3c39df1b6351af890 into 3845ffd4b616fb920e1ef16a61ab3c384e20cd78
commit1b6d5ff09f14cd7eef2cbf20e4c519a70e46f051 authorGitHub Merge Button <merge-button@github.com> dateSun 21 Aug 2011, 22:51 (15 years ago) parent3845ffd1b33e08
5 files changed+115−4
tests/benchmarks/src/Data/Text/Benchmarks.hs+2 tests/benchmarks/src/Data/Text/Benchmarks/Programs/Sort.hs+10−3 tests/benchmarks/src/Data/Text/Benchmarks/Programs/StripTags.hs+3−1 tests/benchmarks/src/Data/Text/Benchmarks/Programs/Throughput.hs+6 tests/benchmarks/src/Data/Text/Benchmarks/Stream.hs+94
tests/benchmarks/src/Data/Text/Benchmarks.hs+2
@@ -19,6 +19,7 @@ import qualified Data.Text.Benchmarks.Pure as Pure
1919import qualified Data.Text.Benchmarks.ReadNumbers as ReadNumbers
2020import qualified Data.Text.Benchmarks.Replace as Replace
2121import qualified Data.Text.Benchmarks.Search as Search
22+import qualified Data.Text.Benchmarks.Stream as Stream
2223import qualified Data.Text.Benchmarks.WordFrequencies as WordFrequencies
2324
2425import qualified Data.Text.Benchmarks.Programs.BigTable as Programs.BigTable
@@ -52,6 +53,7 @@ benchmarks = do
5253 , ReadNumbers.benchmark (tf "numbers.txt")
5354 , Replace.benchmark (tf "russian.txt") "принимая" "своем"
5455 , Search.benchmark (tf "russian.txt") "принимая"
56+ , Stream.benchmark (tf "russian.txt")
5557 , WordFrequencies.benchmark (tf "russian.txt")
5658 ]
5759
tests/benchmarks/src/Data/Text/Benchmarks/Programs/Sort.hs+10−3
@@ -21,15 +21,17 @@ import Criterion (Benchmark, bgroup, bench)
2121import Data.Monoid (mconcat)
2222import System.IO (Handle, hPutStr)
2323import qualified Data.ByteString as B
24+import qualified Data.ByteString.Char8 as BC
2425import qualified Data.ByteString.Lazy as BL
2526import qualified Data.ByteString.Lazy.Char8 as BLC
26−import qualified Data.ByteString.Char8 as BC
2727import qualified Data.List as L
2828import qualified Data.Text as T
29+import qualified Data.Text.Encoding as T
2930import qualified Data.Text.IO as T
3031import qualified Data.Text.Lazy as TL
31−import qualified Data.Text.Lazy.IO as TL
3232import qualified Data.Text.Lazy.Builder as TLB
33+import qualified Data.Text.Lazy.Encoding as TL
34+import qualified Data.Text.Lazy.IO as TL
3335
3436benchmark :: FilePath -> Handle -> IO Benchmark
3537benchmark i o = return $ bgroup "Sort"
@@ -38,7 +40,12 @@ benchmark i o = return $ bgroup "Sort"
3840 , bench "LazyByteString" $ BL.readFile i >>= BL.hPutStr o . lazyByteString
3941 , bench "Text" $ T.readFile i >>= T.hPutStr o . text
4042 , bench "LazyText" $ TL.readFile i >>= TL.hPutStr o . lazyText
41− , bench "TextBuilder" $ T.readFile i >>= TL.hPutStr o . textBuilder
43+ , bench "TextByteString" $ B.readFile i >>=
44+ B.hPutStr o . T.encodeUtf8 . text . T.decodeUtf8
45+ , bench "LazyTextByteString" $ BL.readFile i >>=
46+ BL.hPutStr o . TL.encodeUtf8 . lazyText . TL.decodeUtf8
47+ , bench "TextBuilder" $ B.readFile i >>=
48+ BL.hPutStr o . TL.encodeUtf8 . textBuilder . T.decodeUtf8
4249 ]
4350
4451string :: String -> String
tests/benchmarks/src/Data/Text/Benchmarks/Programs/StripTags.hs+3−1
@@ -22,12 +22,14 @@ import qualified Data.ByteString as B
2222import qualified Data.ByteString.Char8 as BC
2323import qualified Data.Text as T
2424import qualified Data.Text.Encoding as T
25+import qualified Data.Text.IO as T
2526
2627benchmark :: FilePath -> Handle -> IO Benchmark
2728benchmark i o = return $ bgroup "StripTags"
2829 [ bench "String" $ readFile i >>= hPutStr o . string
2930 , bench "ByteString" $ B.readFile i >>= B.hPutStr o . byteString
30− , bench "Text" $
31+ , bench "Text" $ T.readFile i >>= T.hPutStr o . text
32+ , bench "TextByteString" $
3133 B.readFile i >>= B.hPutStr o . T.encodeUtf8 . text . T.decodeUtf8
3234 ]
3335
tests/benchmarks/src/Data/Text/Benchmarks/Programs/Throughput.hs+6
@@ -22,7 +22,9 @@ import Criterion (Benchmark, bgroup, bench)
2222import System.IO (Handle, hPutStr)
2323import qualified Data.ByteString as B
2424import qualified Data.ByteString.Lazy as BL
25+import qualified Data.Text.Encoding as T
2526import qualified Data.Text.IO as T
27+import qualified Data.Text.Lazy.Encoding as TL
2628import qualified Data.Text.Lazy.IO as TL
2729
2830benchmark :: FilePath -> Handle -> IO Benchmark
@@ -32,4 +34,8 @@ benchmark fp sink = return $ bgroup "Throughput"
3234 , bench "LazyByteString" $ BL.readFile fp >>= BL.hPutStr sink
3335 , bench "Text" $ T.readFile fp >>= T.hPutStr sink
3436 , bench "LazyText" $ TL.readFile fp >>= TL.hPutStr sink
37+ , bench "TextByteString" $
38+ B.readFile fp >>= B.hPutStr sink . T.encodeUtf8 . T.decodeUtf8
39+ , bench "LazyTextByteString" $
40+ BL.readFile fp >>= BL.hPutStr sink . TL.encodeUtf8 . TL.decodeUtf8
3541 ]
tests/benchmarks/src/Data/Text/Benchmarks/Stream.hsnew file+94
@@ -0,0 +1,94 @@
1+-- | This module contains a number of benchmarks for the different streaming
2+-- functions
3+--
4+-- Tested in this benchmark:
5+--
6+-- * Most streaming functions
7+--
8+{-# LANGUAGE BangPatterns #-}
9+{-# OPTIONS_GHC -fno-warn-orphans #-}
10+module Data.Text.Benchmarks.Stream
11+ ( benchmark
12+ ) where
13+
14+import Control.DeepSeq (NFData (..))
15+import Criterion (Benchmark, bgroup, bench, nf)
16+import Data.Text.Fusion.Internal (Step (..), Stream (..))
17+import qualified Data.Text.Encoding as T
18+import qualified Data.Text.Encoding.Error as E
19+import qualified Data.Text.Encoding.Fusion as T
20+import qualified Data.Text.Encoding.Fusion.Common as F
21+import qualified Data.Text.Fusion as T
22+import qualified Data.Text.IO as T
23+import qualified Data.Text.Lazy.Encoding as TL
24+import qualified Data.Text.Lazy.Encoding.Fusion as TL
25+import qualified Data.Text.Lazy.Fusion as TL
26+import qualified Data.Text.Lazy.IO as TL
27+
28+instance NFData a => NFData (Stream a) where
29+ -- Currently, this implementation does not force evaluation of the size hint
30+ rnf (Stream next s0 _) = go s0
31+ where
32+ go !s = case next s of
33+ Done -> ()
34+ Skip s' -> go s'
35+ Yield x s' -> rnf x `seq` go s'
36+
37+benchmark :: FilePath -> IO Benchmark
38+benchmark fp = do
39+ -- Different formats
40+ t <- T.readFile fp
41+ let !utf8 = T.encodeUtf8 t
42+ !utf16le = T.encodeUtf16LE t
43+ !utf16be = T.encodeUtf16BE t
44+ !utf32le = T.encodeUtf32LE t
45+ !utf32be = T.encodeUtf32BE t
46+
47+ -- Once again for the lazy variants
48+ tl <- TL.readFile fp
49+ let !utf8L = TL.encodeUtf8 tl
50+ !utf16leL = TL.encodeUtf16LE tl
51+ !utf16beL = TL.encodeUtf16BE tl
52+ !utf32leL = TL.encodeUtf32LE tl
53+ !utf32beL = TL.encodeUtf32BE tl
54+
55+ -- For the functions which operate on streams
56+ let !s = T.stream t
57+
58+ return $ bgroup "Stream"
59+
60+ -- Fusion
61+ [ bgroup "stream" $
62+ [ bench "Text" $ nf T.stream t
63+ , bench "LazyText" $ nf TL.stream tl
64+ ]
65+
66+ -- Encoding.Fusion
67+ , bgroup "streamUtf8"
68+ [ bench "Text" $ nf (T.streamUtf8 E.lenientDecode) utf8
69+ , bench "LazyText" $ nf (TL.streamUtf8 E.lenientDecode) utf8L
70+ ]
71+ , bgroup "streamUtf16LE"
72+ [ bench "Text" $ nf (T.streamUtf16LE E.lenientDecode) utf16le
73+ , bench "LazyText" $ nf (TL.streamUtf16LE E.lenientDecode) utf16leL
74+ ]
75+ , bgroup "streamUtf16BE"
76+ [ bench "Text" $ nf (T.streamUtf16BE E.lenientDecode) utf16be
77+ , bench "LazyText" $ nf (TL.streamUtf16BE E.lenientDecode) utf16beL
78+ ]
79+ , bgroup "streamUtf32LE"
80+ [ bench "Text" $ nf (T.streamUtf32LE E.lenientDecode) utf32le
81+ , bench "LazyText" $ nf (TL.streamUtf32LE E.lenientDecode) utf32leL
82+ ]
83+ , bgroup "streamUtf32BE"
84+ [ bench "Text" $ nf (T.streamUtf32BE E.lenientDecode) utf32be
85+ , bench "LazyText" $ nf (TL.streamUtf32BE E.lenientDecode) utf32beL
86+ ]
87+
88+ -- Encoding.Fusion.Common
89+ , bench "restreamUtf8" $ nf F.restreamUtf8 s
90+ , bench "restreamUtf16LE" $ nf F.restreamUtf16LE s
91+ , bench "restreamUtf16BE" $ nf F.restreamUtf16BE s
92+ , bench "restreamUtf32LE" $ nf F.restreamUtf32LE s
93+ , bench "restreamUtf32BE" $ nf F.restreamUtf32BE s
94+ ]