for in vs for of vs for of Iterator

JavaScript performance comparison

Test case created

Info

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

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = [5,6,7,8];
    a.foo = 'bar';
    var c;
};
</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…

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