on master help sign in
Improve documentation, explain what is tested
afb20f6Jasper Van der Jeugt
tests/benchmarks/src/Data/Text/Benchmarks.hs+4−6
@@ -15,14 +15,13 @@ import qualified Data.Text.Benchmarks.EncodeUtf8 as EncodeUtf8
15import qualified Data.Text.Benchmarks.Equality as Equality
15import qualified Data.Text.Benchmarks.Equality as Equality
16import qualified Data.Text.Benchmarks.FileRead as FileRead
16import qualified Data.Text.Benchmarks.FileRead as FileRead
17import qualified Data.Text.Benchmarks.FoldLines as FoldLines
17import qualified Data.Text.Benchmarks.FoldLines as FoldLines
18−import qualified Data.Text.Benchmarks.HtmlCombinator as HtmlCombinator
19−import qualified Data.Text.Benchmarks.Ordering as Ordering
20import qualified Data.Text.Benchmarks.Pure as Pure
18import qualified Data.Text.Benchmarks.Pure as Pure
21import qualified Data.Text.Benchmarks.ReadNumbers as ReadNumbers
19import qualified Data.Text.Benchmarks.ReadNumbers as ReadNumbers
22import qualified Data.Text.Benchmarks.Replace as Replace
20import qualified Data.Text.Benchmarks.Replace as Replace
23import qualified Data.Text.Benchmarks.Search as Search
21import qualified Data.Text.Benchmarks.Search as Search
24import qualified Data.Text.Benchmarks.WordFrequencies as WordFrequencies
22import qualified Data.Text.Benchmarks.WordFrequencies as WordFrequencies
25
23
24+import qualified Data.Text.Benchmarks.Programs.BigTable as Programs.BigTable
26import qualified Data.Text.Benchmarks.Programs.Cut as Programs.Cut
25import qualified Data.Text.Benchmarks.Programs.Cut as Programs.Cut
27import qualified Data.Text.Benchmarks.Programs.Sort as Programs.Sort
26import qualified Data.Text.Benchmarks.Programs.Sort as Programs.Sort
28import qualified Data.Text.Benchmarks.Programs.StripTags as Programs.StripTags
27import qualified Data.Text.Benchmarks.Programs.StripTags as Programs.StripTags
@@ -40,12 +39,10 @@ benchmarks = do
40 bs <- sequence
39 bs <- sequence
41 [ Builder.benchmark
40 [ Builder.benchmark
42 , DecodeUtf8.benchmark (tf "russian.txt")
41 , DecodeUtf8.benchmark (tf "russian.txt")
43− , EncodeUtf8.benchmark sink "επανάληψη 竺法蘭共譯"
42+ , EncodeUtf8.benchmark "επανάληψη 竺法蘭共譯"
44 , Equality.benchmark (tf "japanese.txt")
43 , Equality.benchmark (tf "japanese.txt")
45 , FileRead.benchmark (tf "russian.txt")
44 , FileRead.benchmark (tf "russian.txt")
46 , FoldLines.benchmark (tf "russian.txt")
45 , FoldLines.benchmark (tf "russian.txt")
47− , HtmlCombinator.benchmark sink
48− , Ordering.benchmark (tf "russian.txt")
49 , Pure.benchmark (tf "japanese.txt")
46 , Pure.benchmark (tf "japanese.txt")
50 , ReadNumbers.benchmark (tf "numbers.txt")
47 , ReadNumbers.benchmark (tf "numbers.txt")
51 , Replace.benchmark (tf "russian.txt") "принимая" "своем"
48 , Replace.benchmark (tf "russian.txt") "принимая" "своем"
@@ -55,7 +52,8 @@ benchmarks = do
55
52
56 -- Program-like benchmarks
53 -- Program-like benchmarks
57 ps <- bgroup "Programs" `fmap` sequence
54 ps <- bgroup "Programs" `fmap` sequence
55+ [ Programs.BigTable.benchmark sink
58− [ Programs.Cut.benchmark (tf "russian.txt") sink 20 40
56+ , Programs.Cut.benchmark (tf "russian.txt") sink 20 40
59 , Programs.Sort.benchmark (tf "russian.txt") sink
57 , Programs.Sort.benchmark (tf "russian.txt") sink
60 , Programs.StripTags.benchmark (tf "yiwiki.xml") sink
58 , Programs.StripTags.benchmark (tf "yiwiki.xml") sink
61 , Programs.Throughput.benchmark (tf "russian.txt") sink
59 , Programs.Throughput.benchmark (tf "russian.txt") sink
tests/benchmarks/src/Data/Text/Benchmarks/Builder.hs+4
@@ -1,5 +1,9 @@
1-- | Testing the internal builder monoid
1-- | Testing the internal builder monoid
2--
2--
3+-- Tested in this benchmark:
4+--
5+-- * Concatenating many small strings using a builder
6+--
3{-# LANGUAGE OverloadedStrings #-}
7{-# LANGUAGE OverloadedStrings #-}
4module Data.Text.Benchmarks.Builder
8module Data.Text.Benchmarks.Builder
5 ( benchmark
9 ( benchmark
tests/benchmarks/src/Data/Text/Benchmarks/DecodeUtf8.hs+14
@@ -1,3 +1,17 @@
1+-- | Test decoding of UTF-8
2+--
3+-- Tested in this benchmark:
4+--
5+-- * Decoding bytes using UTF-8
6+--
7+-- In some tests:
8+--
9+-- * Taking the length of the result
10+--
11+-- * Taking the init of the result
12+--
13+-- The latter are used for testing stream fusion.
14+--
1module Data.Text.Benchmarks.DecodeUtf8
15module Data.Text.Benchmarks.DecodeUtf8
2 ( benchmark
16 ( benchmark
3 ) where
17 ) where
tests/benchmarks/src/Data/Text/Benchmarks/EncodeUtf8.hs+17−17
@@ -1,33 +1,33 @@
1+-- | UTF-8 encode a text
2+--
3+-- Tested in this benchmark:
4+--
5+-- * Replicating a string a number of times
6+--
7+-- * UTF-8 encoding it
8+--
1module Data.Text.Benchmarks.EncodeUtf8
9module Data.Text.Benchmarks.EncodeUtf8
2 ( benchmark
10 ( benchmark
3 ) where
11 ) where
4
12
5−import Criterion (Benchmark, bgroup, bench)
13+import Criterion (Benchmark, bgroup, bench, whnf)
6−import System.IO (Handle, hPutStr)
7import qualified Data.ByteString as B
14import qualified Data.ByteString as B
8import qualified Data.ByteString.Lazy as BL
15import qualified Data.ByteString.Lazy as BL
9import qualified Data.Text as T
16import qualified Data.Text as T
10import qualified Data.Text.Encoding as T
17import qualified Data.Text.Encoding as T
11−import qualified Data.Text.IO as T
12import qualified Data.Text.Lazy as TL
18import qualified Data.Text.Lazy as TL
13import qualified Data.Text.Lazy.Encoding as TL
19import qualified Data.Text.Lazy.Encoding as TL
14−import qualified Data.Text.Lazy.IO as TL
15
20
16−benchmark :: Handle -> String -> IO Benchmark
21+benchmark :: String -> IO Benchmark
22+benchmark string = do
17−benchmark sink string = return $ bgroup "EncodeUtf8"
23+ return $ bgroup "EncodeUtf8"
18− [ bench "String" $ hPutStr sink $ concat $ replicate k string
24+ [ bench "Text" $ whnf (B.length . T.encodeUtf8) text
19− , bench "Text" $ T.hPutStr sink $ T.replicate k text
20− , bench "TextLazy" $ TL.hPutStr sink $
21− TL.replicate (fromIntegral k) lazyText
22− , bench "TextByteString" $ B.hPutStr sink $
23− T.encodeUtf8 $ T.replicate k text
24− , bench "TextByteStringLazy" $ BL.hPutStr sink $
25− TL.encodeUtf8 $ TL.replicate (fromIntegral k) lazyText
25+ , bench "LazyText" $ whnf (BL.length . TL.encodeUtf8) lazyText
26− ]
26+ ]
27 where
27 where
28 -- The string in different formats
28 -- The string in different formats
29− text = T.pack string
29+ text = T.replicate k $ T.pack string
30− lazyText = TL.pack string
30+ lazyText = TL.replicate (fromIntegral k) $ TL.pack string
31
31
32 -- Amount
32 -- Amount
33 k = 100000
33 k = 100000
tests/benchmarks/src/Data/Text/Benchmarks/Equality.hs+5−2
@@ -1,9 +1,12 @@
1-- | Compare a string with a copy of itself that is identical except
1-- | Compare a string with a copy of itself that is identical except
2-- for the last character.
2-- for the last character.
3--
3--
4+-- Tested in this benchmark:
5+--
6+-- * Comparison of strings (Eq instance)
7+--
4module Data.Text.Benchmarks.Equality
8module Data.Text.Benchmarks.Equality
5− (
6− benchmark
9+ ( benchmark
7 ) where
10 ) where
8
11
9import Criterion (Benchmark, bgroup, bench, whnf)
12import Criterion (Benchmark, bgroup, bench, whnf)
tests/benchmarks/src/Data/Text/Benchmarks/FileRead.hs+4
@@ -1,5 +1,9 @@
1-- | Benchmarks simple file reading
1-- | Benchmarks simple file reading
2--
2--
3+-- Tested in this benchmark:
4+--
5+-- * Reading a file from the disk
6+--
3module Data.Text.Benchmarks.FileRead
7module Data.Text.Benchmarks.FileRead
4 ( benchmark
8 ( benchmark
5 ) where
9 ) where
tests/benchmarks/src/Data/Text/Benchmarks/FoldLines.hs+5−1
@@ -1,6 +1,10 @@
1-- | Read a file line-by-line using handles, and perform a fold over the lines.
1-- | Read a file line-by-line using handles, and perform a fold over the lines.
2-- The fold is used here to calculate the number of lines in the file.
2-- The fold is used here to calculate the number of lines in the file.
3--
3--
4+-- Tested in this benchmark:
5+--
6+-- * Buffered, line-based IO
7+--
4{-# LANGUAGE BangPatterns #-}
8{-# LANGUAGE BangPatterns #-}
5module Data.Text.Benchmarks.FoldLines
9module Data.Text.Benchmarks.FoldLines
6 ( benchmark
10 ( benchmark
@@ -14,7 +18,7 @@ import qualified Data.Text.IO as T
14
18
15benchmark :: FilePath -> IO Benchmark
19benchmark :: FilePath -> IO Benchmark
16benchmark fp = return $ bgroup "ReadLines"
20benchmark fp = return $ bgroup "ReadLines"
17− [ bench "Text" $ withHandle $ foldLinesT (\n _ -> n + 1) (0 :: Int)
21+ [ bench "Text" $ withHandle $ foldLinesT (\n _ -> n + 1) (0 :: Int)
18 , bench "ByteString" $ withHandle $ foldLinesB (\n _ -> n + 1) (0 :: Int)
22 , bench "ByteString" $ withHandle $ foldLinesB (\n _ -> n + 1) (0 :: Int)
19 ]
23 ]
20 where
24 where
tests/benchmarks/src/Data/Text/Benchmarks/HtmlCombinator.hs → tests/benchmarks/src/Data/Text/Benchmarks/Programs/BigTable.hsrenamed+8−2
@@ -1,7 +1,13 @@
1-- | Create a large HTML table and dump it to a handle
1-- | Create a large HTML table and dump it to a handle
2--
2--
3+-- Tested in this benchmark:
4+--
5+-- * Creating a large HTML document using a builder
6+--
7+-- * Writing to a handle
8+--
3{-# LANGUAGE OverloadedStrings #-}
9{-# LANGUAGE OverloadedStrings #-}
4−module Data.Text.Benchmarks.HtmlCombinator
10+module Data.Text.Benchmarks.Programs.BigTable
5 ( benchmark
11 ( benchmark
6 ) where
12 ) where
7
13
@@ -13,7 +19,7 @@ import System.IO (Handle)
13import qualified Data.Text as T
19import qualified Data.Text as T
14
20
15benchmark :: Handle -> IO Benchmark
21benchmark :: Handle -> IO Benchmark
16−benchmark sink = return $ bench "HtmlCombinator" $ do
22+benchmark sink = return $ bench "BigTable" $ do
17 hPutStr sink "Content-Type: text/html\n\n<table>"
23 hPutStr sink "Content-Type: text/html\n\n<table>"
18 hPutStr sink . toLazyText . makeTable =<< rows
24 hPutStr sink . toLazyText . makeTable =<< rows
19 hPutStr sink "</table>"
25 hPutStr sink "</table>"
tests/benchmarks/src/Data/Text/Benchmarks/Programs/Cut.hs+12
@@ -1,5 +1,17 @@
1-- | Cut into a file, selecting certain columns (e.g. columns 10 to 40)
1-- | Cut into a file, selecting certain columns (e.g. columns 10 to 40)
2--
2--
3+-- Tested in this benchmark:
4+--
5+-- * Reading the file
6+--
7+-- * Splitting into lines
8+--
9+-- * Taking a number of characters from the lines
10+--
11+-- * Joining the lines
12+--
13+-- * Writing back to a handle
14+--
3module Data.Text.Benchmarks.Programs.Cut
15module Data.Text.Benchmarks.Programs.Cut
4 ( benchmark
16 ( benchmark
5 ) where
17 ) where
tests/benchmarks/src/Data/Text/Benchmarks/Programs/Sort.hs+12
@@ -1,5 +1,17 @@
1-- | This benchmark sorts the lines of a file, like the @sort@ unix utility.
1-- | This benchmark sorts the lines of a file, like the @sort@ unix utility.
2--
2--
3+-- Tested in this benchmark:
4+--
5+-- * Reading the file
6+--
7+-- * Splitting into lines
8+--
9+-- * Sorting the lines
10+--
11+-- * Joining the lines
12+--
13+-- * Writing back to a handle
14+--
3{-# LANGUAGE OverloadedStrings #-}
15{-# LANGUAGE OverloadedStrings #-}
4module Data.Text.Benchmarks.Programs.Sort
16module Data.Text.Benchmarks.Programs.Sort
5 ( benchmark
17 ( benchmark
tests/benchmarks/src/Data/Text/Benchmarks/Programs/StripTags.hs+8
@@ -2,6 +2,14 @@
2--
2--
3-- This program was originally contributed by Petr Prokhorenkov.
3-- This program was originally contributed by Petr Prokhorenkov.
4--
4--
5+-- Tested in this benchmark:
6+--
7+-- * Reading the file
8+--
9+-- * Replacing text between HTML tags (<>) with whitespace
10+--
11+-- * Writing back to a handle
12+--
5{-# OPTIONS_GHC -fspec-constr-count=5 #-}
13{-# OPTIONS_GHC -fspec-constr-count=5 #-}
6module Data.Text.Benchmarks.Programs.StripTags
14module Data.Text.Benchmarks.Programs.StripTags
7 ( benchmark
15 ( benchmark
tests/benchmarks/src/Data/Text/Benchmarks/Programs/Throughput.hs+8
@@ -6,6 +6,14 @@
6-- do any actual encoding/decoding here, while String and Text do have UTF-8
6-- do any actual encoding/decoding here, while String and Text do have UTF-8
7-- encoding/decoding.
7-- encoding/decoding.
8--
8--
9+-- Tested in this benchmark:
10+--
11+-- * Reading the file
12+--
13+-- * Replacing text between HTML tags (<>) with whitespace
14+--
15+-- * Writing back to a handle
16+--
9module Data.Text.Benchmarks.Programs.Throughput
17module Data.Text.Benchmarks.Programs.Throughput
10 ( benchmark
18 ( benchmark
11 ) where
19 ) where
tests/benchmarks/src/Data/Text/Benchmarks/Pure.hs+4
@@ -1,5 +1,9 @@
1-- | Benchmarks various pure functions from the Text library
1-- | Benchmarks various pure functions from the Text library
2--
2--
3+-- Tested in this benchmark:
4+--
5+-- * Most pure functions defined the string types
6+--
3{-# LANGUAGE BangPatterns, GADTs, MagicHash #-}
7{-# LANGUAGE BangPatterns, GADTs, MagicHash #-}
4{-# OPTIONS_GHC -fno-warn-orphans #-}
8{-# OPTIONS_GHC -fno-warn-orphans #-}
5module Data.Text.Benchmarks.Pure
9module Data.Text.Benchmarks.Pure
tests/benchmarks/src/Data/Text/Benchmarks/ReadNumbers.hs+11−9
@@ -12,6 +12,10 @@
12-- The different benchmarks will only take into account the values they can
12-- The different benchmarks will only take into account the values they can
13-- parse.
13-- parse.
14--
14--
15+-- Tested in this benchmark:
16+--
17+-- * Lexing/parsing of different numerical types
18+--
15module Data.Text.Benchmarks.ReadNumbers
19module Data.Text.Benchmarks.ReadNumbers
16 ( benchmark
20 ( benchmark
17 ) where
21 ) where
@@ -40,14 +44,14 @@ benchmark fp = do
40 b <- B.lines `fmap` B.readFile fp
44 b <- B.lines `fmap` B.readFile fp
41 bl <- BL.lines `fmap` BL.readFile fp
45 bl <- BL.lines `fmap` BL.readFile fp
42 return $ bgroup "ReadNumbers"
46 return $ bgroup "ReadNumbers"
43− [ bench "DecimalString" $ whnf (int . string readDec) s
47+ [ bench "DecimalString" $ whnf (int . string readDec) s
44 , bench "HexadecimalString" $ whnf (int . string readHex) s
48 , bench "HexadecimalString" $ whnf (int . string readHex) s
45− , bench "DoubleString" $ whnf (double . string readFloat) s
49+ , bench "DoubleString" $ whnf (double . string readFloat) s
46
50
47− , bench "DecimalText" $ whnf (int . text (T.signed T.decimal)) t
51+ , bench "DecimalText" $ whnf (int . text (T.signed T.decimal)) t
48 , bench "HexadecimalText" $ whnf (int . text (T.signed T.hexadecimal)) t
52 , bench "HexadecimalText" $ whnf (int . text (T.signed T.hexadecimal)) t
49− , bench "DoubleText" $ whnf (double . text T.double) t
53+ , bench "DoubleText" $ whnf (double . text T.double) t
50− , bench "RationalText" $ whnf (double . text T.rational) t
54+ , bench "RationalText" $ whnf (double . text T.rational) t
51
55
52 , bench "DecimalLazyText" $
56 , bench "DecimalLazyText" $
53 whnf (int . text (TL.signed TL.decimal)) tl
57 whnf (int . text (TL.signed TL.decimal)) tl
@@ -58,10 +62,8 @@ benchmark fp = do
58 , bench "RationalLazyText" $
62 , bench "RationalLazyText" $
59 whnf (double . text TL.rational) tl
63 whnf (double . text TL.rational) tl
60
64
61− , bench "DecimalByteString" $
62− whnf (int . byteString B.readInt) b
65+ , bench "DecimalByteString" $ whnf (int . byteString B.readInt) b
63− , bench "DoubleByteString" $
64− whnf (double . byteString B.readDouble) b
66+ , bench "DoubleByteString" $ whnf (double . byteString B.readDouble) b
65
67
66 , bench "DecimalLazyByteString" $
68 , bench "DecimalLazyByteString" $
67 whnf (int . byteString BL.readInt) bl
69 whnf (int . byteString BL.readInt) bl
tests/benchmarks/src/Data/Text/Benchmarks/Replace.hs+4
@@ -1,5 +1,9 @@
1-- | Replace a string by another string
1-- | Replace a string by another string
2--
2--
3+-- Tested in this benchmark:
4+--
5+-- * Search and replace of a pattern in a text
6+--
3module Data.Text.Benchmarks.Replace
7module Data.Text.Benchmarks.Replace
4 ( benchmark
8 ( benchmark
5 ) where
9 ) where
tests/benchmarks/src/Data/Text/Benchmarks/Search.hs+4
@@ -1,5 +1,9 @@
1-- | Search for a pattern in a file, find the number of occurences
1-- | Search for a pattern in a file, find the number of occurences
2--
2--
3+-- Tested in this benchmark:
4+--
5+-- * Searching all occurences of a pattern using library routines
6+--
3module Data.Text.Benchmarks.Search
7module Data.Text.Benchmarks.Search
4 ( benchmark
8 ( benchmark
5 ) where
9 ) where
tests/benchmarks/src/Data/Text/Benchmarks/WordFrequencies.hs+8
@@ -1,5 +1,13 @@
1-- | A word frequency count using the different string types
1-- | A word frequency count using the different string types
2--
2--
3+-- Tested in this benchmark:
4+--
5+-- * Splitting into words
6+--
7+-- * Converting to lowercase
8+--
9+-- * Comparing: Eq/Ord instances
10+--
3module Data.Text.Benchmarks.WordFrequencies
11module Data.Text.Benchmarks.WordFrequencies
4 ( benchmark
12 ( benchmark
5 ) where
13 ) where