On a 64-bit OS with an i5-3570k, this piece of code takes 1.19 seconds on average to execute:
for (int i = 0; i < 1e9; i++);
If 1e9
is replaced with 1000000000
or (int)1e9
, it only takes 0.0013 seconds on average to execute.
To me, it's fairly intuitive that comparing doubles is slower, when taken into consideration that doubles are more complex and take up double the memory of ints, but why is it so much slower?