Commits

Jasper Van der Jeugt  committed 6ba95f6

Separate group for program-like benchmarks

  • Participants
  • Parent commits 4447e56

Comments (0)

Files changed (3)

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

     ( main
     ) where
 
-import Criterion.Main (Benchmark, defaultMain)
+import Criterion.Main (Benchmark, defaultMain, bgroup)
 import System.FilePath ((</>))
 import System.IO (IOMode (WriteMode), openFile, hSetEncoding, utf8)
 
 import qualified Data.Text.Benchmarks.Builder as Builder
 import qualified Data.Text.Benchmarks.CaseMap as CaseMap
-import qualified Data.Text.Benchmarks.Cut as Cut
 import qualified Data.Text.Benchmarks.DecodeUtf8 as DecodeUtf8
 import qualified Data.Text.Benchmarks.EncodeUtf8 as EncodeUtf8
 import qualified Data.Text.Benchmarks.Equality as Equality
 import qualified Data.Text.Benchmarks.StripBrackets as StripBrackets
 import qualified Data.Text.Benchmarks.WordCount as WordCount
 
+import qualified Data.Text.Benchmarks.Programs.Cut as Programs.Cut
+
 main :: IO ()
 main = benchmarks >>= defaultMain
 
 benchmarks = do
     sink <- openFile "/dev/null" WriteMode
     hSetEncoding sink utf8
-    sequence
+
+    -- Traditional benchmarks
+    bs <- sequence
         [ Builder.benchmark
         , CaseMap.benchmark (tf "russian.txt") sink
-        , Cut.benchmark (tf "russian.txt") sink 30 60
         , DecodeUtf8.benchmark (tf "russian.txt")
         , EncodeUtf8.benchmark sink "επανάληψη 竺法蘭共譯"
         , Equality.benchmark (tf "japanese.txt")
         , StripBrackets.benchmark (tf "russian.txt") sink
         , WordCount.benchmark (tf "russian.txt")
         ]
+
+    -- Program-like benchmarks
+    ps <- bgroup "Programs" `fmap` sequence
+        [ Programs.Cut.benchmark (tf "russian.txt") sink 20 40
+        ]
+
+    return $ bs ++ [ps]
   where
     -- Location of a test file
     tf = ("../text/test" </>)

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

--- | Cut into a file, selecting certain columns (e.g. lines 10 to 40)
---
-module Data.Text.Benchmarks.Cut
-    ( benchmark
-    ) where
-
-import Criterion (Benchmark, bgroup, bench)
-import System.IO (Handle, hPutStr)
-import qualified Data.ByteString as B
-import qualified Data.ByteString.Char8 as BC
-import qualified Data.ByteString.Lazy as BL
-import qualified Data.ByteString.Lazy.Char8 as BLC
-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 :: FilePath -> Handle -> Int -> Int -> IO Benchmark
-benchmark p sink from to = return $ bgroup "Cut"
-    [ bench' "String" string
-    , bench' "ByteString" byteString
-    , bench' "LazyByteString" lazyByteString
-    , bench' "Text" text
-    , bench' "LazyText" lazyText
-    , bench' "TextByteString" textByteString
-    , bench' "LazyTextByteString" lazyTextByteString
-    ]
-  where
-    bench' n s = bench n (s p sink from to)
-
-string :: FilePath -> Handle -> Int -> Int -> IO ()
-string fp sink from to = do
-    s <- readFile fp
-    hPutStr sink $ cut s
-  where
-    cut = unlines . map (take (to - from) . drop from) . lines
-
-byteString :: FilePath -> Handle -> Int -> Int -> IO ()
-byteString fp sink from to = do
-    bs <- B.readFile fp
-    B.hPutStr sink $ cut bs
-  where
-    cut = BC.unlines . map (B.take (to - from) . B.drop from) . BC.lines
-
-lazyByteString :: FilePath -> Handle -> Int -> Int -> IO ()
-lazyByteString fp sink from to = do
-    bs <- BL.readFile fp
-    BL.hPutStr sink $ cut bs
-  where
-    cut = BLC.unlines . map (BL.take (to' - from') . BL.drop from') . BLC.lines
-    from' = fromIntegral from
-    to' = fromIntegral to
-
-text :: FilePath -> Handle -> Int -> Int -> IO ()
-text fp sink from to = do
-    t <- T.readFile fp
-    T.hPutStr sink $ cut t
-  where
-    cut = T.unlines . map (T.take (to - from) . T.drop from) . T.lines
-
-lazyText :: FilePath -> Handle -> Int -> Int -> IO ()
-lazyText fp sink from to = do
-    t <- TL.readFile fp
-    TL.hPutStr sink $ cut t
-  where
-    cut = TL.unlines . map (TL.take (to' - from') . TL.drop from') . TL.lines
-    from' = fromIntegral from
-    to' = fromIntegral to
-
-textByteString :: FilePath -> Handle -> Int -> Int -> IO ()
-textByteString fp sink from to = do
-    t <- T.decodeUtf8 `fmap` B.readFile fp
-    B.hPutStr sink $ T.encodeUtf8 $ cut t
-  where
-    cut = T.unlines . map (T.take (to - from) . T.drop from) . T.lines
-
-lazyTextByteString :: FilePath -> Handle -> Int -> Int -> IO ()
-lazyTextByteString fp sink from to = do
-    t <- TL.decodeUtf8 `fmap` BL.readFile fp
-    BL.hPutStr sink $ TL.encodeUtf8 $ cut t
-  where
-    cut = TL.unlines . map (TL.take (to' - from') . TL.drop from') . TL.lines
-    from' = fromIntegral from
-    to' = fromIntegral to

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

+-- | Cut into a file, selecting certain columns (e.g. columns 10 to 40)
+--
+module Data.Text.Benchmarks.Programs.Cut
+    ( benchmark
+    ) where
+
+import Criterion (Benchmark, bgroup, bench)
+import System.IO (Handle, hPutStr)
+import qualified Data.ByteString as B
+import qualified Data.ByteString.Char8 as BC
+import qualified Data.ByteString.Lazy as BL
+import qualified Data.ByteString.Lazy.Char8 as BLC
+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 :: FilePath -> Handle -> Int -> Int -> IO Benchmark
+benchmark p sink from to = return $ bgroup "Cut"
+    [ bench' "String" string
+    , bench' "ByteString" byteString
+    , bench' "LazyByteString" lazyByteString
+    , bench' "Text" text
+    , bench' "LazyText" lazyText
+    , bench' "TextByteString" textByteString
+    , bench' "LazyTextByteString" lazyTextByteString
+    ]
+  where
+    bench' n s = bench n (s p sink from to)
+
+string :: FilePath -> Handle -> Int -> Int -> IO ()
+string fp sink from to = do
+    s <- readFile fp
+    hPutStr sink $ cut s
+  where
+    cut = unlines . map (take (to - from) . drop from) . lines
+
+byteString :: FilePath -> Handle -> Int -> Int -> IO ()
+byteString fp sink from to = do
+    bs <- B.readFile fp
+    B.hPutStr sink $ cut bs
+  where
+    cut = BC.unlines . map (B.take (to - from) . B.drop from) . BC.lines
+
+lazyByteString :: FilePath -> Handle -> Int -> Int -> IO ()
+lazyByteString fp sink from to = do
+    bs <- BL.readFile fp
+    BL.hPutStr sink $ cut bs
+  where
+    cut = BLC.unlines . map (BL.take (to' - from') . BL.drop from') . BLC.lines
+    from' = fromIntegral from
+    to' = fromIntegral to
+
+text :: FilePath -> Handle -> Int -> Int -> IO ()
+text fp sink from to = do
+    t <- T.readFile fp
+    T.hPutStr sink $ cut t
+  where
+    cut = T.unlines . map (T.take (to - from) . T.drop from) . T.lines
+
+lazyText :: FilePath -> Handle -> Int -> Int -> IO ()
+lazyText fp sink from to = do
+    t <- TL.readFile fp
+    TL.hPutStr sink $ cut t
+  where
+    cut = TL.unlines . map (TL.take (to' - from') . TL.drop from') . TL.lines
+    from' = fromIntegral from
+    to' = fromIntegral to
+
+textByteString :: FilePath -> Handle -> Int -> Int -> IO ()
+textByteString fp sink from to = do
+    t <- T.decodeUtf8 `fmap` B.readFile fp
+    B.hPutStr sink $ T.encodeUtf8 $ cut t
+  where
+    cut = T.unlines . map (T.take (to - from) . T.drop from) . T.lines
+
+lazyTextByteString :: FilePath -> Handle -> Int -> Int -> IO ()
+lazyTextByteString fp sink from to = do
+    t <- TL.decodeUtf8 `fmap` BL.readFile fp
+    BL.hPutStr sink $ TL.encodeUtf8 $ cut t
+  where
+    cut = TL.unlines . map (TL.take (to' - from') . TL.drop from') . TL.lines
+    from' = fromIntegral from
+    to' = fromIntegral to