for in or for

JavaScript performance comparison

Revision 10 of this test case created by

Preparation code

<script>
  var i, value, keys;
  var objectA = {};
  var objectB = {};

  for (i = 0; i < 100; ++i) {
    objectA[i] = 'test';
  }

  for (i = 0; i < 1000; ++i) {
    objectB[i] = 'test';
  }
</script>
    

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
for in 100
for (i in objectA) {
  value = objectA[i];
}
pending…
for-in 1000
for (i in objectB) {
  value = objectB[i];
}
pending…
for 100
keys = Object.keys(objectA);

for (i = 0; i < keys.length; i++) {
  value = objectA[keys[i]];
}
pending…
for 1000
keys = Object.keys(objectB);

for (i = 0; i < keys.length; i++) {
  value = objectB[keys[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.

0 Comments