I read about IO buffering in the "Real World Haskell" (ch. 7, p. 189), and tried to test, how different buffering size affects the performance.
import System.IO
import Data.Time.Clock
import Data.Char(toUpper)
main :: IO ()
main = do
hInp <- openFile "bigFile.txt" ReadMode
let bufferSize = truncate $ 2**10
hSetBuffering hInp (BlockBuffering (Just bufferSize))
bufferMode <- hGetBuffering hInp
putStrLn $ "Current buffering mode: " ++ (show bufferMode)
startTime <- getCurrentTime
inp <- hGetContents hInp
writeFile "processed.txt" (map toUpper inp)
hClose hInp
finishTime <- getCurrentTime
print $ diffUTCTime finishTime startTime
return ()
Then I created a "bigFile.txt"
-rw-rw-r-- 1 user user 96M янв. 26 09:49 bigFile.txt
and run my program against this file, with different buffer size:
Current buffering mode: BlockBuffering (Just 32)
9.744967s
Current buffering mode: BlockBuffering (Just 1024)
9.667924s
Current buffering mode: BlockBuffering (Just 1048576)
9.494807s
Current buffering mode: BlockBuffering (Just 1073741824)
9.792453s
But the program running time is almost the same. Is it normal, or I'm doing something wrong?