[Haskell-cafe] First call to putStr takes far more time than subsequent calls
ben.gunton at gmail.com
Thu Jul 9 20:17:50 UTC 2015
This is a simplified version of an issue I'm running into when timing some
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.
Relevant code: http://lpaste.net/136250
What's going on here?
import Control.Monadimport Data.Time.Clock
main :: IO ()main = do
-- putStr ""
replicateM_ 5 $ do
t1 <- getCurrentTime
t2 <- getCurrentTime
print . round $ 1000 * 1000 * diffUTCTime t2 t1
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe