Permalink
Browse files

Just for completeness, a read-file benchmark

  • Loading branch information...
1 parent 0e1e37b commit 0a1966a432972f28669ab058dd2115b4e79efd81 @bos committed Jan 26, 2011
Showing with 31 additions and 0 deletions.
  1. +31 −0 benchmarks/ReadFile.hs
View
@@ -0,0 +1,31 @@
+{-# LANGUAGE BangPatterns, OverloadedStrings #-}
+
+import Control.DeepSeq
+import Control.Exception
+import Control.Monad
+import Data.Aeson
+import Data.Aeson.Parser
+import Data.Attoparsec
+import Data.Time.Clock
+import System.Environment (getArgs)
+import System.IO
+import qualified Data.ByteString as B
+
+main = do
+ (cnt:args) <- getArgs
+ let count = read cnt :: Int
+ forM_ args $ \arg -> bracket (openFile arg ReadMode) hClose $ \h -> do
+ putStrLn $ arg ++ ":"
+ start <- getCurrentTime
+ let loop !n
+ | n >= count = return ()
+ | otherwise = do
+ let go = do
+ s <- B.hGet h 16384
+ if B.null s
+ then loop (n+1)
+ else go
+ go
+ loop 0
+ end <- getCurrentTime
+ putStrLn $ " " ++ show (diffUTCTime end start)

0 comments on commit 0a1966a

Please sign in to comment.