Interesting timings follow...
(timings are in milliseconds but the absolute numbers don't matter - they depend on your computer speed)
===============================================
for vs. while smackdown
//for loop iteration
for (var i=0, j=500000; i<j; i++) {}
//while loop iteration
var i=500000; while (i--) {}
FF3 IE7 SAF3 OP9.5 OP9.2x
for 45 94 47 78 135
while 24 39 31 47 96
===============================================
===============================================
pre/post increment/decrement
conclusion: They're all the same
//setup code
var i=500000, j=5;
//i--
while(i-- > j) {}
//--i
while(--i >= j) {}
//i++
while(j++ < i) {}
//++i
while(++j <= i) {}
FF3 IE7 SAF3 OP9.5 OP9.2x
i-- 30 78 47 62 125
--i 28 78 47 62 125
i++ 31 78 47 63 125
++i 28 63 47 70 125
===============================================
===============================================
(see for in intrigue for the back story on this one)
//setup code
var obj = {}, i = 100000; //size varies
while (i--) { obj['x'+i] = 42; }
//timed code 1:
for (var key in obj) {
}
//timed code 2:
for (var key in obj) {
if (obj.hasOwnProperty(key)) {}
}
//timed code 3:
for (var key in obj) {
if (typeof(obj[key]) !== 'function') {}
}
Timed code 1:
obj size FF3 IE7 SAF3 OP9.5 OP9.2x
1000: 1 1 1 1 24
10000: 3 16 16 24 5547
100000: 41 782 156 610 632390
1000000: 462 67203 3000 30437 n/a
Timed code 2:
obj size FF3 IE7 SAF3 OP9.5 OP9.2x
1000: 1 1 1 1 31
10000: 5 47 16 31 5484
100000: 57 1172 187 1094 753781
1000000: 686 70687 3234 43055 n/a
Timed code 3:
obj size FF3 IE7 SAF3 OP9.5 OP9.2x
1000: 1 1 1 1 16
10000: 5 31 16 31 6406
100000: 69 1562 266 859 765719
1000000: 700 132453 6312 52141 n/a
Conclusions:
1) Adding a hasOwnProperty() check to for/in iteration has a neglibible
impact on performance, especially for real-world sub-1000 member objects.
2) Firefox has an efficient implementation of accessing objects where
a single access takes about the same time regardless of object size.
Other browsers have exponential timing where a single access of an
object member takes longer if the object is bigger.
3) Opera implemented some badly needed js engine updates in version 9.5
but is still not a front-runner.
===============================================
