Iterating over object properties (v14)

Revision 14 of this benchmark created by Jerry on


Description

Comparing various approaches to iterating over an object's enumerable properties.

Setup

var object = {};
    for (var i = 0; i < 100; ++i) {
      object['user' + i] = 'user' + i;
    }
    var foo;

Test runner

Ready to run.

Testing in
TestOps/sec
for…in
for (var property in object) {
  if (object.hasOwnProperty(property)) {
    foo = object[property];
  }
}
ready
for…in with continue
for (var property in object) {
  if (!object.hasOwnProperty(property)) continue;
  foo = object[property];
}
ready
Filtering with Object.keys
Object.keys(object).forEach(function(key) {
  foo = key;
});
ready
sdf
var rs = [],
  arr = Object.keys(object);
arr.forEach(function(key) {
  foo = key
});
ready
var rs = [],
  arr = Object.keys(object);

while (key = arr.shift()) {
  foo = key;
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.