The following code results in slow1 = 1323 ms
, slow2 = 1311 ms
and fast = 897 ms
. How is that possible?
Here: Nested or not nested if-blocks? they mention that
Any modern compiler, and by that I mean anything built in the past 20 years, will compile these to the same code.
let s = System.Diagnostics.Stopwatch()
let mutable a = 1
s.Start()
for i in 0 .. 1000000000 do
if i < 0 then
if i < 0 then
a <- 4
printfn "fast = %d" s.ElapsedMilliseconds
s.Restart()
for i in 0 .. 1000000000 do
if i < 0 && i < 0 then
a <- 4
printfn "slow1 = %d" s.ElapsedMilliseconds
s.Restart()
for i in 0 .. 1000000000 do
if i < 0 & i < 0 then
a <- 4
printfn "slow2 = %d" s.ElapsedMilliseconds