Iterating over object properties (v13)

Revision 13 of this benchmark created 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

Revisions

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