for in vs for of vs for of Iterator

JavaScript performance comparison

Revision 5 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 = [], i;
    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
var c=[];
for(i in a) {
  c.push(a[i]);
}
pending…
for of
var c=[];
for(i of a) {c.push(i)}
pending…
for of iterator
var c=[];
for([,i] of Iterator(a)) {c.push(i)}
pending…
for of arr
var c = [i for(i of a)]
pending…
for of iterator
var c = [i for([,i] of Iterator(a))]
pending…
keys
var keys = Object.keys(a), c = [];
for(var i=0; i<keys.length; i++) {
    c = a[keys[i]];
}
pending…
filter
var c = Object.keys(a).filter(i => 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