for in or for

JavaScript performance comparison

Test case created by Oliver Caldwell

Preparation code

<script>
  var targetObj = new Object();
 
  for (var i = 0; i < 20; i++) {
   targetObj[i] = 'Filler';
  }
</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 targetObj) {
 console.log(targetObj[i]);
}
pending…
for
for (var i = 0; i < targetObj.length; i++) {
 console.log(targetObj[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:

1 comment

Oliver Caldwell (revision owner) commented :

Wow, Spark is going to get one hell of a speed boost :D

Add a comment