Typing this directly into the console I saw the same thing. However, if I wrap it in a function the order switches.
All sorts of possible reasons. Perhaps the JIT compiler can only work on functions. Or maybe it's because local variables are faster than globals. I haven't bothered digging any further.
Try:
Code:
var fn = function() {
var r = [], sum = 0, time;
for (var i = 0 ; i < 100000 ; i++) {
r.push(i);
}
time = new Date().getTime();
Ext.Array.each(r, function(rec) {
sum += rec;
});
console.log(sum, new Date().getTime() - time);
sum = 0;
time = new Date().getTime();
for (var i = 0, len = r.length ; i < len ; i++) { // Note caching the length
sum += r[i];
}
console.log(sum, new Date().getTime() - time);
};
fn();