on master help sign in
Add Streaming benchmarks
commit6aa834a7ed3f8898ac75f90ca6181cda97a2ecf3 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSat 13 Aug 2011, 12:09 (15 years ago) parent3845ffd
2 files changed+45
tests/benchmarks/src/Data/Text/Benchmarks.hs+2 tests/benchmarks/src/Data/Text/Benchmarks/Stream.hs+43
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/Stream.hsnew file+43
@@ -0,0 +1,43 @@
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.ByteString as B
18+import qualified Data.ByteString.Lazy as BL
19+import qualified Data.Text.Encoding.Error as E
20+import qualified Data.Text.Encoding.Fusion as T
21+import qualified Data.Text.Lazy.Encoding.Fusion as TL
22+
23+instance NFData a => NFData (Stream a) where
24+ -- Currently, this implementation does not force evaluation of the size hint
25+ rnf (Stream next s0 _) = go s0
26+ where
27+ go !s = case next s of
28+ Done -> ()
29+ Skip s' -> go s'
30+ Yield x s' -> rnf x `seq` go s'
31+
32+benchmark :: FilePath -> IO Benchmark
33+benchmark fp = do
34+ -- Load data
35+ bs <- B.readFile fp
36+ lbs <- BL.readFile fp
37+
38+ return $ bgroup "Stream"
39+ [ bgroup "streamUtf8"
40+ [ bench "Text" $ nf (T.streamUtf8 E.lenientDecode) bs
41+ , bench "LazyText" $ nf (TL.streamUtf8 E.lenientDecode) lbs
42+ ]
43+ ]