on master help sign in
Clean up FoldLines benchmark a bit
cc24e80Jasper Van der Jeugt
tests/benchmarks/src/Data/Text/Benchmarks/FoldLines.hs+5−4
@@ -1,4 +1,5 @@
1−-- | Fold over the lines in a file
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--
3--
3{-# LANGUAGE BangPatterns #-}
4{-# LANGUAGE BangPatterns #-}
4module Data.Text.Benchmarks.FoldLines
5module Data.Text.Benchmarks.FoldLines
@@ -12,8 +13,8 @@ import qualified Data.Text as T
12import qualified Data.Text.IO as T
13import qualified Data.Text.IO as T
13
14
14benchmark :: FilePath -> IO Benchmark
15benchmark :: FilePath -> IO Benchmark
15−benchmark fp = return $ bgroup "FoldLines"
16+benchmark fp = return $ bgroup "ReadLines"
16− [ bench "Text" $ withHandle $ foldLinesT (\n _ -> n + 1) (0 :: Int)
17+ [ bench "Text" $ withHandle $ foldLinesT (\n _ -> n + 1) (0 :: Int)
17 , bench "ByteString" $ withHandle $ foldLinesB (\n _ -> n + 1) (0 :: Int)
18 , bench "ByteString" $ withHandle $ foldLinesB (\n _ -> n + 1) (0 :: Int)
18 ]
19 ]
19 where
20 where
@@ -24,7 +25,7 @@ benchmark fp = return $ bgroup "FoldLines"
24 hClose h
25 hClose h
25 return x
26 return x
26
27
27−-- Text line fold
28+-- | Text line fold
28--
29--
29foldLinesT :: (a -> T.Text -> a) -> a -> Handle -> IO a
30foldLinesT :: (a -> T.Text -> a) -> a -> Handle -> IO a
30foldLinesT f z0 h = go z0
31foldLinesT f z0 h = go z0