keys vs array

JavaScript performance comparison

Test case created

Preparation code

<script>
  var o = {};
  for (var i = 0; i < 1000; i++) {
    o[i] = i;
  }
</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
keys
var a = Object.keys(o);
pending…
arr
var a = [];
for (var k in o) {
  if (o.hasOwnProperty(k)) a.push[k];
}
pending…
arr without test
var a = [];
for (var k in o) {
 a.push(k);
}
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