for in vs Object.keys + for (v2)

Revision 2 of this benchmark created by an@nym.ous on


Setup

//create object w/lots of properties
    var obj = {};
    for (var i = 0; i < 1000; i++) {
      obj[i] = true;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
for in
var val;

for (var prop in obj) {
  val = obj[prop];
}
ready
for Object.keys
var arr = Object.keys(obj),
  len = arr.length,
  val;

for (var i = 0; i < len; ++i) {
  val = obj[arr[i]];
}
ready

Revisions

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

  • Revision 1: published by Jason on
  • Revision 2: published by an@nym.ous on