for in vs for of vs for of Iterator

JavaScript performance comparison

Revision 4 of this test case created

Info

Check performance of for in and for of constructs. Firefox only

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = [], c;
    for(var i=1; i<=10000; i++) a.push(i);
    a.b = 12;
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
for in
for(var i in a) {
  c = a[i];
}
pending…
for of
for(c of a) {}
pending…
for of iterator
for([,c] of Iterator(a)) {}
pending…
for in arr
var arr1 = [];
for(var i in a) {
  arr1.push(a[i]);
}
pending…
for of arr
[c for(c of a)]
pending…
for of iterator
[c for([,c] of Iterator(a))]
pending…
double-semicolon
for(var i=0; i<a.length; i++) {
    c = a[i];
}
pending…
double-semicolon comprehension
var arr1 = [];
for(var i=0; i<a.length; i++) {
    arr1.push(a[i]);
}
pending…
keys
var keys = Object.keys(a);
for(var i=0; i<keys.length; i++) {
    c = a[keys[i]];
}
pending…
double-semicolon 2
for(var i=0, max = a.length; i < max; i++) {
    c = a[i];
}
pending…
double-semicolon 3
for(var i=0; c = a[i++];) {
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment