I'm testing the performance of this recursive Haskell function, which repeatedly sums the first 100000000 integers of an infinite list (using a Conduit pipeline) and prints the elapsed time of each execution:
import Conduit
import Data.Time.Clock
evaluate_listC 0 = return ()
evaluate_listC i = do
startTime <- getCurrentTime
print $ runConduitPure $ yieldMany [1..] .| takeC 100000000 .| sumC
endTime <- getCurrentTime
print $ diffUTCTime endTime startTime
evaluate_listC (i-1)
Compiling (with -O flag) and running the code, and iterating the function 10 times, I obtain the following execution times:
38.2066878s
4.3696857s
1.3367605s
0.9950032s
0.9399968s
0.9039936s
0.9079987s
0.9119587s
0.9090151s
0.8749654s
Why does the first iteration (and also the second) take more time while the following ones are incredibly faster?