This is a simplified version of an issue I'm running into when timing some functions.
In this example, the first putStr inside the replicateM_ takes far longer than subsequent putStrs. If I add in a putStr at the top (the commented line), each iteration takes the same. (Though I presume I just shifted the long execution to the putStr on top).
The same thing happens on the first iterations of a function when I need to evaluate some state, or deepseq some value. putStr was just a simpler version that still showed the same issue.
What's going on here?
Thanks!
import Control.Monad
import Data.Time.Clock
main :: IO ()
main = do
-- putStr ""
replicateM_ 5 $ do
t1 <- getCurrentTime
putStr ""
t2 <- getCurrentTime
print . round $ 1000 * 1000 * diffUTCTime t2 t1
{-
Sample output:
49
1
1
1
2
-}