Commits

Jasper Van der Jeugt  committed 18b543f

Improve documentation, explain what is tested

  • Participants
  • Parent commits 8cd50d2

Comments (0)

Files changed (18)

File tests/benchmarks/src/Data/Text/Benchmarks.hs

 import qualified Data.Text.Benchmarks.Equality as Equality
 import qualified Data.Text.Benchmarks.FileRead as FileRead
 import qualified Data.Text.Benchmarks.FoldLines as FoldLines
-import qualified Data.Text.Benchmarks.HtmlCombinator as HtmlCombinator
-import qualified Data.Text.Benchmarks.Ordering as Ordering
 import qualified Data.Text.Benchmarks.Pure as Pure
 import qualified Data.Text.Benchmarks.ReadNumbers as ReadNumbers
 import qualified Data.Text.Benchmarks.Replace as Replace
 import qualified Data.Text.Benchmarks.Search as Search
 import qualified Data.Text.Benchmarks.WordFrequencies as WordFrequencies
 
+import qualified Data.Text.Benchmarks.Programs.BigTable as Programs.BigTable
 import qualified Data.Text.Benchmarks.Programs.Cut as Programs.Cut
 import qualified Data.Text.Benchmarks.Programs.Sort as Programs.Sort
 import qualified Data.Text.Benchmarks.Programs.StripTags as Programs.StripTags
     bs <- sequence
         [ Builder.benchmark
         , DecodeUtf8.benchmark (tf "russian.txt")
-        , EncodeUtf8.benchmark sink "επανάληψη 竺法蘭共譯"
+        , EncodeUtf8.benchmark "επανάληψη 竺法蘭共譯"
         , Equality.benchmark (tf "japanese.txt")
         , FileRead.benchmark (tf "russian.txt")
         , FoldLines.benchmark (tf "russian.txt")
-        , HtmlCombinator.benchmark sink
-        , Ordering.benchmark (tf "russian.txt")
         , Pure.benchmark (tf "japanese.txt")
         , ReadNumbers.benchmark (tf "numbers.txt")
         , Replace.benchmark (tf "russian.txt") "принимая" "своем"
 
     -- Program-like benchmarks
     ps <- bgroup "Programs" `fmap` sequence
-        [ Programs.Cut.benchmark (tf "russian.txt") sink 20 40
+        [ Programs.BigTable.benchmark sink
+        , Programs.Cut.benchmark (tf "russian.txt") sink 20 40
         , Programs.Sort.benchmark (tf "russian.txt") sink
         , Programs.StripTags.benchmark (tf "yiwiki.xml") sink
         , Programs.Throughput.benchmark (tf "russian.txt") sink

File tests/benchmarks/src/Data/Text/Benchmarks/Builder.hs

 -- | Testing the internal builder monoid
 --
+-- Tested in this benchmark:
+--
+-- * Concatenating many small strings using a builder
+--
 {-# LANGUAGE OverloadedStrings #-}
 module Data.Text.Benchmarks.Builder
     ( benchmark

File tests/benchmarks/src/Data/Text/Benchmarks/DecodeUtf8.hs

+-- | Test decoding of UTF-8
+--
+-- Tested in this benchmark:
+--
+-- * Decoding bytes using UTF-8
+--
+-- In some tests:
+--
+-- * Taking the length of the result
+--
+-- * Taking the init of the result
+--
+-- The latter are used for testing stream fusion.
+--
 module Data.Text.Benchmarks.DecodeUtf8
     ( benchmark
     ) where

File tests/benchmarks/src/Data/Text/Benchmarks/EncodeUtf8.hs

+-- | UTF-8 encode a text
+--
+-- Tested in this benchmark:
+--
+-- * Replicating a string a number of times
+--
+-- * UTF-8 encoding it
+--
 module Data.Text.Benchmarks.EncodeUtf8
     ( benchmark
     ) where
 
-import Criterion (Benchmark, bgroup, bench)
-import System.IO (Handle, hPutStr)
+import Criterion (Benchmark, bgroup, bench, whnf)
 import qualified Data.ByteString as B
 import qualified Data.ByteString.Lazy as BL
 import qualified Data.Text as T
 import qualified Data.Text.Encoding as T
-import qualified Data.Text.IO as T
 import qualified Data.Text.Lazy as TL
 import qualified Data.Text.Lazy.Encoding as TL
-import qualified Data.Text.Lazy.IO as TL
 
-benchmark :: Handle -> String -> IO Benchmark
-benchmark sink string = return $ bgroup "EncodeUtf8"
-    [ bench "String" $ hPutStr sink $ concat $ replicate k string
-    , bench "Text" $ T.hPutStr sink $ T.replicate k text
-    , bench "TextLazy" $ TL.hPutStr sink $
-        TL.replicate (fromIntegral k) lazyText
-    , bench "TextByteString" $ B.hPutStr sink $
-        T.encodeUtf8 $ T.replicate k text
-    , bench "TextByteStringLazy" $ BL.hPutStr sink $
-        TL.encodeUtf8 $ TL.replicate (fromIntegral k) lazyText
-    ]
+benchmark :: String -> IO Benchmark
+benchmark string = do
+    return $ bgroup "EncodeUtf8"
+        [ bench "Text"     $ whnf (B.length . T.encodeUtf8)   text
+        , bench "LazyText" $ whnf (BL.length . TL.encodeUtf8) lazyText
+        ]
   where
     -- The string in different formats
-    text = T.pack string
-    lazyText = TL.pack string
+    text = T.replicate k $ T.pack string
+    lazyText = TL.replicate (fromIntegral k) $ TL.pack string
 
     -- Amount
     k = 100000

File tests/benchmarks/src/Data/Text/Benchmarks/Equality.hs

 -- | Compare a string with a copy of itself that is identical except
 -- for the last character.
 --
+-- Tested in this benchmark:
+--
+-- * Comparison of strings (Eq instance)
+--
 module Data.Text.Benchmarks.Equality
-    (
-      benchmark
+    ( benchmark
     ) where
 
 import Criterion (Benchmark, bgroup, bench, whnf)

File tests/benchmarks/src/Data/Text/Benchmarks/FileRead.hs

 -- | Benchmarks simple file reading
 --
+-- Tested in this benchmark:
+--
+-- * Reading a file from the disk
+--
 module Data.Text.Benchmarks.FileRead
     ( benchmark
     ) where

File tests/benchmarks/src/Data/Text/Benchmarks/FoldLines.hs

 -- | Read a file line-by-line using handles, and perform a fold over the lines.
 -- The fold is used here to calculate the number of lines in the file.
 --
+-- Tested in this benchmark:
+--
+-- * Buffered, line-based IO
+--
 {-# LANGUAGE BangPatterns #-}
 module Data.Text.Benchmarks.FoldLines
     ( benchmark
 
 benchmark :: FilePath -> IO Benchmark
 benchmark fp = return $ bgroup "ReadLines"
-    [ bench "Text" $       withHandle $ foldLinesT (\n _ -> n + 1) (0 :: Int)
+    [ bench "Text"       $ withHandle $ foldLinesT (\n _ -> n + 1) (0 :: Int)
     , bench "ByteString" $ withHandle $ foldLinesB (\n _ -> n + 1) (0 :: Int)
     ]
   where

File tests/benchmarks/src/Data/Text/Benchmarks/HtmlCombinator.hs

--- | Create a large HTML table and dump it to a handle
---
-{-# LANGUAGE OverloadedStrings #-}
-module Data.Text.Benchmarks.HtmlCombinator
-    ( benchmark
-    ) where
-
-import Criterion (Benchmark, bench)
-import Data.Monoid (mappend, mconcat)
-import Data.Text.Lazy.Builder (Builder, fromText, toLazyText)
-import Data.Text.Lazy.IO (hPutStr)
-import System.IO (Handle)
-import qualified Data.Text as T
-
-benchmark :: Handle -> IO Benchmark
-benchmark sink = return $ bench "HtmlCombinator" $ do
-    hPutStr sink "Content-Type: text/html\n\n<table>"
-    hPutStr sink . toLazyText . makeTable =<< rows
-    hPutStr sink "</table>"
-  where
-    -- We provide the number of rows in IO so the builder value isn't shared
-    -- between the benchmark samples.
-    rows :: IO Int
-    rows = return 20000
-    {-# NOINLINE rows #-}
-
-makeTable :: Int -> Builder
-makeTable n = mconcat $ replicate n $ mconcat $ map makeCol [1 .. 50]
-
-makeCol :: Int -> Builder
-makeCol 1 = fromText "<tr><td>1</td>"
-makeCol 50 = fromText "<td>50</td></tr>"
-makeCol i = fromText "<td>" `mappend` (fromInt i `mappend` fromText "</td>")
-
-fromInt :: Int -> Builder
-fromInt = fromText . T.pack . show

File tests/benchmarks/src/Data/Text/Benchmarks/Programs/BigTable.hs

+-- | Create a large HTML table and dump it to a handle
+--
+-- Tested in this benchmark:
+--
+-- * Creating a large HTML document using a builder
+--
+-- * Writing to a handle
+--
+{-# LANGUAGE OverloadedStrings #-}
+module Data.Text.Benchmarks.Programs.BigTable
+    ( benchmark
+    ) where
+
+import Criterion (Benchmark, bench)
+import Data.Monoid (mappend, mconcat)
+import Data.Text.Lazy.Builder (Builder, fromText, toLazyText)
+import Data.Text.Lazy.IO (hPutStr)
+import System.IO (Handle)
+import qualified Data.Text as T
+
+benchmark :: Handle -> IO Benchmark
+benchmark sink = return $ bench "BigTable" $ do
+    hPutStr sink "Content-Type: text/html\n\n<table>"
+    hPutStr sink . toLazyText . makeTable =<< rows
+    hPutStr sink "</table>"
+  where
+    -- We provide the number of rows in IO so the builder value isn't shared
+    -- between the benchmark samples.
+    rows :: IO Int
+    rows = return 20000
+    {-# NOINLINE rows #-}
+
+makeTable :: Int -> Builder
+makeTable n = mconcat $ replicate n $ mconcat $ map makeCol [1 .. 50]
+
+makeCol :: Int -> Builder
+makeCol 1 = fromText "<tr><td>1</td>"
+makeCol 50 = fromText "<td>50</td></tr>"
+makeCol i = fromText "<td>" `mappend` (fromInt i `mappend` fromText "</td>")
+
+fromInt :: Int -> Builder
+fromInt = fromText . T.pack . show

File tests/benchmarks/src/Data/Text/Benchmarks/Programs/Cut.hs

 -- | Cut into a file, selecting certain columns (e.g. columns 10 to 40)
 --
+-- Tested in this benchmark:
+--
+-- * Reading the file
+--
+-- * Splitting into lines
+--
+-- * Taking a number of characters from the lines
+--
+-- * Joining the lines
+--
+-- * Writing back to a handle
+--
 module Data.Text.Benchmarks.Programs.Cut
     ( benchmark
     ) where

File tests/benchmarks/src/Data/Text/Benchmarks/Programs/Sort.hs

 -- | This benchmark sorts the lines of a file, like the @sort@ unix utility.
 --
+-- Tested in this benchmark:
+--
+-- * Reading the file
+--
+-- * Splitting into lines
+--
+-- * Sorting the lines
+--
+-- * Joining the lines
+--
+-- * Writing back to a handle
+--
 {-# LANGUAGE OverloadedStrings #-}
 module Data.Text.Benchmarks.Programs.Sort
     ( benchmark

File tests/benchmarks/src/Data/Text/Benchmarks/Programs/StripTags.hs

 --
 -- This program was originally contributed by Petr Prokhorenkov.
 --
+-- Tested in this benchmark:
+--
+-- * Reading the file
+--
+-- * Replacing text between HTML tags (<>) with whitespace
+--
+-- * Writing back to a handle
+--
 {-# OPTIONS_GHC -fspec-constr-count=5 #-}
 module Data.Text.Benchmarks.Programs.StripTags
     ( benchmark

File tests/benchmarks/src/Data/Text/Benchmarks/Programs/Throughput.hs

 -- do any actual encoding/decoding here, while String and Text do have UTF-8
 -- encoding/decoding.
 --
+-- Tested in this benchmark:
+--
+-- * Reading the file
+--
+-- * Replacing text between HTML tags (<>) with whitespace
+--
+-- * Writing back to a handle
+--
 module Data.Text.Benchmarks.Programs.Throughput
     ( benchmark
     ) where

File tests/benchmarks/src/Data/Text/Benchmarks/Pure.hs

 -- | Benchmarks various pure functions from the Text library
 --
+-- Tested in this benchmark:
+--
+-- * Most pure functions defined the string types
+--
 {-# LANGUAGE BangPatterns, GADTs, MagicHash #-}
 {-# OPTIONS_GHC -fno-warn-orphans #-}
 module Data.Text.Benchmarks.Pure

File tests/benchmarks/src/Data/Text/Benchmarks/ReadNumbers.hs

 -- The different benchmarks will only take into account the values they can
 -- parse.
 --
+-- Tested in this benchmark:
+--
+-- * Lexing/parsing of different numerical types
+--
 module Data.Text.Benchmarks.ReadNumbers
     ( benchmark
     ) where
     b <- B.lines `fmap` B.readFile fp
     bl <- BL.lines `fmap` BL.readFile fp
     return $ bgroup "ReadNumbers"
-        [ bench "DecimalString" $     whnf (int . string readDec) s
+        [ bench "DecimalString"     $ whnf (int . string readDec) s
         , bench "HexadecimalString" $ whnf (int . string readHex) s
-        , bench "DoubleString" $      whnf (double . string readFloat) s
+        , bench "DoubleString"      $ whnf (double . string readFloat) s
 
-        , bench "DecimalText" $     whnf (int . text (T.signed T.decimal)) t
+        , bench "DecimalText"     $ whnf (int . text (T.signed T.decimal)) t
         , bench "HexadecimalText" $ whnf (int . text (T.signed T.hexadecimal)) t
-        , bench "DoubleText" $      whnf (double . text T.double) t
-        , bench "RationalText" $    whnf (double . text T.rational) t
+        , bench "DoubleText"      $ whnf (double . text T.double) t
+        , bench "RationalText"    $ whnf (double . text T.rational) t
 
         , bench "DecimalLazyText" $
             whnf (int . text (TL.signed TL.decimal)) tl
         , bench "RationalLazyText" $
             whnf (double . text TL.rational) tl
 
-        , bench "DecimalByteString" $
-            whnf (int . byteString B.readInt) b
-        , bench "DoubleByteString" $
-            whnf (double . byteString B.readDouble) b
+        , bench "DecimalByteString" $ whnf (int . byteString B.readInt) b
+        , bench "DoubleByteString"  $ whnf (double . byteString B.readDouble) b
 
         , bench "DecimalLazyByteString" $
             whnf (int . byteString BL.readInt) bl

File tests/benchmarks/src/Data/Text/Benchmarks/Replace.hs

 -- | Replace a string by another string
 --
+-- Tested in this benchmark:
+--
+-- * Search and replace of a pattern in a text
+--
 module Data.Text.Benchmarks.Replace
     ( benchmark
     ) where

File tests/benchmarks/src/Data/Text/Benchmarks/Search.hs

 -- | Search for a pattern in a file, find the number of occurences
 --
+-- Tested in this benchmark:
+--
+-- * Searching all occurences of a pattern using library routines
+--
 module Data.Text.Benchmarks.Search
     ( benchmark
     ) where

File tests/benchmarks/src/Data/Text/Benchmarks/WordFrequencies.hs

 -- | A word frequency count using the different string types
 --
+-- Tested in this benchmark:
+--
+-- * Splitting into words
+--
+-- * Converting to lowercase
+--
+-- * Comparing: Eq/Ord instances
+--
 module Data.Text.Benchmarks.WordFrequencies
     ( benchmark
     ) where