Object.keys+pop vs for in for values

JavaScript performance comparison

Revision 53 of this test case created

Preparation code

<script>

</script>
<script>
Benchmark.prototype.setup = function() {
    var keys = Object.keys;
    var hasOwnProperty = Object.prototype.hasOwnProperty;
   
    var obj = {};
   
    for(var i=0; i<20; i++) // force dictionary mode
       obj['prop'+i] = 'value'+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
Object.keys && pop()
var props = keys(obj),
  v = null,
  values = [];

while (v = props.pop()) values.push(obj[v]);
pending…
for-in w/ hasOwnProperty
var values = [];
for (var prop in obj) {
  if (obj.hasOwnProperty(prop)) {
    values.push(obj[prop]);
  }
}
pending…
for-in
var values = [];
for (var prop in obj) {
    values.push(obj[prop]);
}
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