I play with the F # Interactive Console and compare the runtime of some numerical operations. In this code, the total runtime seems to double only by repeating the declaration of a single variable.
In VS 2010, I:
open System.Diagnostics let mutable a=1
Then I select this below and run it with Alt + Enter
let stopWatch = Stopwatch.StartNew() for i=1 to 200100100 do a <- a + 1 stopWatch.Stop() printfn "stopWatch.Elapsed: %f" stopWatch.Elapsed.TotalMilliseconds
More or less required: 320 ms
Now I select this and press Alt + Enter:
let mutable a=1 let stopWatch = Stopwatch.StartNew() for i=1 to 200100100 do a <- a + 1 stopWatch.Stop() printfn "stopWatch.Elapsed: %f" stopWatch.Elapsed.TotalMilliseconds
almost double: 620 ms
The same block, but containing the declaration at the top, almost doubles. Shouldn't this be the same since I declare a variable before the stopwatch .StartNew ()? Is it connected to an interactive console? I have the same results using the #time directive.
source share