on master help sign in
Improve documentation, explain what is tested
commitafb20f6417ed3429f7887149a9e5e039b7b453b8 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSat 11 Jun 2011, 15:00 (15 years ago) parentcaaa43b
17 files changed+132−37
tests/benchmarks/src/Data/Text/Benchmarks.hs+4−6 tests/benchmarks/src/Data/Text/Benchmarks/Builder.hs+4 tests/benchmarks/src/Data/Text/Benchmarks/DecodeUtf8.hs+14 tests/benchmarks/src/Data/Text/Benchmarks/EncodeUtf8.hs+17−17 tests/benchmarks/src/Data/Text/Benchmarks/Equality.hs+5−2 tests/benchmarks/src/Data/Text/Benchmarks/FileRead.hs+4 tests/benchmarks/src/Data/Text/Benchmarks/FoldLines.hs+5−1 tests/benchmarks/src/Data/Text/Benchmarks/HtmlCombinator.hs → tests/benchmarks/src/Data/Text/Benchmarks/Programs/BigTable.hs+8−2 tests/benchmarks/src/Data/Text/Benchmarks/Programs/Cut.hs+12 tests/benchmarks/src/Data/Text/Benchmarks/Programs/Sort.hs+12 tests/benchmarks/src/Data/Text/Benchmarks/Programs/StripTags.hs+8 tests/benchmarks/src/Data/Text/Benchmarks/Programs/Throughput.hs+8 tests/benchmarks/src/Data/Text/Benchmarks/Pure.hs+4 tests/benchmarks/src/Data/Text/Benchmarks/ReadNumbers.hs+11−9 tests/benchmarks/src/Data/Text/Benchmarks/Replace.hs+4 tests/benchmarks/src/Data/Text/Benchmarks/Search.hs+4 tests/benchmarks/src/Data/Text/Benchmarks/WordFrequencies.hs+8
tests/benchmarks/src/Data/Text/Benchmarks.hs+4−6
@@ -15,14 +15,13 @@ import qualified Data.Text.Benchmarks.EncodeUtf8 as EncodeUtf8
1515import qualified Data.Text.Benchmarks.Equality as Equality
1616import qualified Data.Text.Benchmarks.FileRead as FileRead
1717import 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
2018import qualified Data.Text.Benchmarks.Pure as Pure
2119import qualified Data.Text.Benchmarks.ReadNumbers as ReadNumbers
2220import qualified Data.Text.Benchmarks.Replace as Replace
2321import qualified Data.Text.Benchmarks.Search as Search
2422import qualified Data.Text.Benchmarks.WordFrequencies as WordFrequencies
2523
24+import qualified Data.Text.Benchmarks.Programs.BigTable as Programs.BigTable
2625import qualified Data.Text.Benchmarks.Programs.Cut as Programs.Cut
2726import qualified Data.Text.Benchmarks.Programs.Sort as Programs.Sort
2827import qualified Data.Text.Benchmarks.Programs.StripTags as Programs.StripTags
@@ -40,12 +39,10 @@ benchmarks = do
4039 bs <- sequence
4140 [ Builder.benchmark
4241 , DecodeUtf8.benchmark (tf "russian.txt")
43− , EncodeUtf8.benchmark sink "επανάληψη 竺法蘭共譯"
42+ , EncodeUtf8.benchmark "επανάληψη 竺法蘭共譯"
4443 , Equality.benchmark (tf "japanese.txt")
4544 , FileRead.benchmark (tf "russian.txt")
4645 , FoldLines.benchmark (tf "russian.txt")
47− , HtmlCombinator.benchmark sink
48− , Ordering.benchmark (tf "russian.txt")
4946 , Pure.benchmark (tf "japanese.txt")
5047 , ReadNumbers.benchmark (tf "numbers.txt")
5148 , Replace.benchmark (tf "russian.txt") "принимая" "своем"
@@ -55,7 +52,8 @@ benchmarks = do
5552
5653 -- Program-like benchmarks
5754 ps <- bgroup "Programs" `fmap` sequence
58− [ Programs.Cut.benchmark (tf "russian.txt") sink 20 40
55+ [ Programs.BigTable.benchmark sink
56+ , Programs.Cut.benchmark (tf "russian.txt") sink 20 40
5957 , Programs.Sort.benchmark (tf "russian.txt") sink
6058 , Programs.StripTags.benchmark (tf "yiwiki.xml") sink
6159 , Programs.Throughput.benchmark (tf "russian.txt") sink
tests/benchmarks/src/Data/Text/Benchmarks/Builder.hs+4
@@ -1,5 +1,9 @@
11-- | Testing the internal builder monoid
22--
3+-- Tested in this benchmark:
4+--
5+-- * Concatenating many small strings using a builder
6+--
37{-# LANGUAGE OverloadedStrings #-}
48module Data.Text.Benchmarks.Builder
59 ( 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+--
115module Data.Text.Benchmarks.DecodeUtf8
216 ( benchmark
317 ) 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+--
19module Data.Text.Benchmarks.EncodeUtf8
210 ( benchmark
311 ) where
412
5−import Criterion (Benchmark, bgroup, bench)
6−import System.IO (Handle, hPutStr)
13+import Criterion (Benchmark, bgroup, bench, whnf)
714import qualified Data.ByteString as B
815import qualified Data.ByteString.Lazy as BL
916import qualified Data.Text as T
1017import qualified Data.Text.Encoding as T
11−import qualified Data.Text.IO as T
1218import qualified Data.Text.Lazy as TL
1319import qualified Data.Text.Lazy.Encoding as TL
14−import qualified Data.Text.Lazy.IO as TL
1520
16−benchmark :: Handle -> String -> IO Benchmark
17−benchmark sink string = return $ bgroup "EncodeUtf8"
18− [ bench "String" $ hPutStr sink $ concat $ replicate k string
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
26− ]
21+benchmark :: String -> IO Benchmark
22+benchmark string = do
23+ return $ bgroup "EncodeUtf8"
24+ [ bench "Text" $ whnf (B.length . T.encodeUtf8) text
25+ , bench "LazyText" $ whnf (BL.length . TL.encodeUtf8) lazyText
26+ ]
2727 where
2828 -- The string in different formats
29− text = T.pack string
30− lazyText = TL.pack string
29+ text = T.replicate k $ T.pack string
30+ lazyText = TL.replicate (fromIntegral k) $ TL.pack string
3131
3232 -- Amount
3333 k = 100000
tests/benchmarks/src/Data/Text/Benchmarks/Equality.hs+5−2
@@ -1,9 +1,12 @@
11-- | Compare a string with a copy of itself that is identical except
22-- for the last character.
33--
4+-- Tested in this benchmark:
5+--
6+-- * Comparison of strings (Eq instance)
7+--
48module Data.Text.Benchmarks.Equality
5− (
6− benchmark
9+ ( benchmark
710 ) where
811
912import Criterion (Benchmark, bgroup, bench, whnf)
tests/benchmarks/src/Data/Text/Benchmarks/FileRead.hs+4
@@ -1,5 +1,9 @@
11-- | Benchmarks simple file reading
22--
3+-- Tested in this benchmark:
4+--
5+-- * Reading a file from the disk
6+--
37module Data.Text.Benchmarks.FileRead
48 ( benchmark
59 ) where
tests/benchmarks/src/Data/Text/Benchmarks/FoldLines.hs+5−1
@@ -1,6 +1,10 @@
11-- | Read a file line-by-line using handles, and perform a fold over the lines.
22-- The fold is used here to calculate the number of lines in the file.
33--
4+-- Tested in this benchmark:
5+--
6+-- * Buffered, line-based IO
7+--
48{-# LANGUAGE BangPatterns #-}
59module Data.Text.Benchmarks.FoldLines
610 ( benchmark
@@ -14,7 +18,7 @@ import qualified Data.Text.IO as T
1418
1519benchmark :: FilePath -> IO Benchmark
1620benchmark fp = return $ bgroup "ReadLines"
17− [ bench "Text" $ withHandle $ foldLinesT (\n _ -> n + 1) (0 :: Int)
21+ [ bench "Text" $ withHandle $ foldLinesT (\n _ -> n + 1) (0 :: Int)
1822 , bench "ByteString" $ withHandle $ foldLinesB (\n _ -> n + 1) (0 :: Int)
1923 ]
2024 where
tests/benchmarks/src/Data/Text/Benchmarks/HtmlCombinator.hs → tests/benchmarks/src/Data/Text/Benchmarks/Programs/BigTable.hsrenamed+8−2
@@ -1,7 +1,13 @@
11-- | Create a large HTML table and dump it to a handle
22--
3+-- Tested in this benchmark:
4+--
5+-- * Creating a large HTML document using a builder
6+--
7+-- * Writing to a handle
8+--
39{-# LANGUAGE OverloadedStrings #-}
4−module Data.Text.Benchmarks.HtmlCombinator
10+module Data.Text.Benchmarks.Programs.BigTable
511 ( benchmark
612 ) where
713
@@ -13,7 +19,7 @@ import System.IO (Handle)
1319import qualified Data.Text as T
1420
1521benchmark :: Handle -> IO Benchmark
16−benchmark sink = return $ bench "HtmlCombinator" $ do
22+benchmark sink = return $ bench "BigTable" $ do
1723 hPutStr sink "Content-Type: text/html\n\n<table>"
1824 hPutStr sink . toLazyText . makeTable =<< rows
1925 hPutStr sink "</table>"
tests/benchmarks/src/Data/Text/Benchmarks/Programs/Cut.hs+12
@@ -1,5 +1,17 @@
11-- | Cut into a file, selecting certain columns (e.g. columns 10 to 40)
22--
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+--
315module Data.Text.Benchmarks.Programs.Cut
416 ( benchmark
517 ) where
tests/benchmarks/src/Data/Text/Benchmarks/Programs/Sort.hs+12
@@ -1,5 +1,17 @@
11-- | This benchmark sorts the lines of a file, like the @sort@ unix utility.
22--
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+--
315{-# LANGUAGE OverloadedStrings #-}
416module Data.Text.Benchmarks.Programs.Sort
517 ( benchmark
tests/benchmarks/src/Data/Text/Benchmarks/Programs/StripTags.hs+8
@@ -2,6 +2,14 @@
22--
33-- This program was originally contributed by Petr Prokhorenkov.
44--
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+--
513{-# OPTIONS_GHC -fspec-constr-count=5 #-}
614module Data.Text.Benchmarks.Programs.StripTags
715 ( benchmark
tests/benchmarks/src/Data/Text/Benchmarks/Programs/Throughput.hs+8
@@ -6,6 +6,14 @@
66-- do any actual encoding/decoding here, while String and Text do have UTF-8
77-- encoding/decoding.
88--
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+--
917module Data.Text.Benchmarks.Programs.Throughput
1018 ( benchmark
1119 ) where
tests/benchmarks/src/Data/Text/Benchmarks/Pure.hs+4
@@ -1,5 +1,9 @@
11-- | Benchmarks various pure functions from the Text library
22--
3+-- Tested in this benchmark:
4+--
5+-- * Most pure functions defined the string types
6+--
37{-# LANGUAGE BangPatterns, GADTs, MagicHash #-}
48{-# OPTIONS_GHC -fno-warn-orphans #-}
59module Data.Text.Benchmarks.Pure
tests/benchmarks/src/Data/Text/Benchmarks/ReadNumbers.hs+11−9
@@ -12,6 +12,10 @@
1212-- The different benchmarks will only take into account the values they can
1313-- parse.
1414--
15+-- Tested in this benchmark:
16+--
17+-- * Lexing/parsing of different numerical types
18+--
1519module Data.Text.Benchmarks.ReadNumbers
1620 ( benchmark
1721 ) where
@@ -40,14 +44,14 @@ benchmark fp = do
4044 b <- B.lines `fmap` B.readFile fp
4145 bl <- BL.lines `fmap` BL.readFile fp
4246 return $ bgroup "ReadNumbers"
43− [ bench "DecimalString" $ whnf (int . string readDec) s
47+ [ bench "DecimalString" $ whnf (int . string readDec) s
4448 , bench "HexadecimalString" $ whnf (int . string readHex) s
45− , bench "DoubleString" $ whnf (double . string readFloat) s
49+ , bench "DoubleString" $ whnf (double . string readFloat) s
4650
47− , bench "DecimalText" $ whnf (int . text (T.signed T.decimal)) t
51+ , bench "DecimalText" $ whnf (int . text (T.signed T.decimal)) t
4852 , bench "HexadecimalText" $ whnf (int . text (T.signed T.hexadecimal)) t
49− , bench "DoubleText" $ whnf (double . text T.double) t
50− , bench "RationalText" $ whnf (double . text T.rational) t
53+ , bench "DoubleText" $ whnf (double . text T.double) t
54+ , bench "RationalText" $ whnf (double . text T.rational) t
5155
5256 , bench "DecimalLazyText" $
5357 whnf (int . text (TL.signed TL.decimal)) tl
@@ -58,10 +62,8 @@ benchmark fp = do
5862 , bench "RationalLazyText" $
5963 whnf (double . text TL.rational) tl
6064
61− , bench "DecimalByteString" $
62− whnf (int . byteString B.readInt) b
63− , bench "DoubleByteString" $
64− whnf (double . byteString B.readDouble) b
65+ , bench "DecimalByteString" $ whnf (int . byteString B.readInt) b
66+ , bench "DoubleByteString" $ whnf (double . byteString B.readDouble) b
6567
6668 , bench "DecimalLazyByteString" $
6769 whnf (int . byteString BL.readInt) bl
tests/benchmarks/src/Data/Text/Benchmarks/Replace.hs+4
@@ -1,5 +1,9 @@
11-- | Replace a string by another string
22--
3+-- Tested in this benchmark:
4+--
5+-- * Search and replace of a pattern in a text
6+--
37module Data.Text.Benchmarks.Replace
48 ( benchmark
59 ) where
tests/benchmarks/src/Data/Text/Benchmarks/Search.hs+4
@@ -1,5 +1,9 @@
11-- | Search for a pattern in a file, find the number of occurences
22--
3+-- Tested in this benchmark:
4+--
5+-- * Searching all occurences of a pattern using library routines
6+--
37module Data.Text.Benchmarks.Search
48 ( benchmark
59 ) where
tests/benchmarks/src/Data/Text/Benchmarks/WordFrequencies.hs+8
@@ -1,5 +1,13 @@
11-- | A word frequency count using the different string types
22--
3+-- Tested in this benchmark:
4+--
5+-- * Splitting into words
6+--
7+-- * Converting to lowercase
8+--
9+-- * Comparing: Eq/Ord instances
10+--
311module Data.Text.Benchmarks.WordFrequencies
412 ( benchmark
513 ) where