Object.keys+pop vs for in for values

JavaScript performance comparison

Revision 52 of this test case created by Victor

Preparation code


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;

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]);
for-in w/ hasOwnProperty
var values = [];
for (var prop in obj) {
  if (obj.hasOwnProperty(prop)) {

Compare results of other browsers


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:


Add a comment