@@ -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.
23--
34{-# LANGUAGE BangPatterns #-}
45module Data.Text.Benchmarks.FoldLines
@@ -12,8 +13,8 @@ import qualified Data.Text as T
1213import qualified Data.Text.IO as T
1314
1415benchmark :: FilePath -> IO Benchmark
15−benchmark fp = return $ bgroup "FoldLines"
16− [ bench "Text" $ withHandle $ foldLinesT (\n _ -> n + 1) (0 :: Int)
16+benchmark fp = return $ bgroup "ReadLines"
17+ [ bench "Text" $ withHandle $ foldLinesT (\n _ -> n + 1) (0 :: Int)
1718 , bench "ByteString" $ withHandle $ foldLinesB (\n _ -> n + 1) (0 :: Int)
1819 ]
1920 where
@@ -24,7 +25,7 @@ benchmark fp = return $ bgroup "FoldLines"
2425 hClose h
2526 return x
2627
27−-- Text line fold
28+-- | Text line fold
2829--
2930foldLinesT :: (a -> T.Text -> a) -> a -> Handle -> IO a
3031foldLinesT f z0 h = go z0