Without optimizations , why "while" is faster than "for"?

127 points gffkii

I noticed, many times, that in debug profile "while" is always faster than "for" (taking about looping over a range and getting sum/multi/etc)

​

For example, this code... 'let mut result:u64 = 0;

let mut number:u64 = 1;

while (number < 10000000) {

result += number;

number += 1;

}

​

is about 2x faster than...

let mut result:u64 = 0

for number in 10000000) {

result += number;

}

Why is that? It clear that for does more things, but being +2x slower!!!