object.keys vs for in (v16)

Revision 16 of this benchmark created by jacob on


Setup

var obj = {
      a: 0,
      b: 1,
      c: 2,
      d: 3,
      e: 4,
      f: 5,
      g: 6,
      h: 7,
      i: 8,
      j: 9
    };
    var sum = 0;

Teardown


    console.log(sum);
  

Test runner

Ready to run.

Testing in
TestOps/sec
1
var keys = Object.keys(obj);
for (var i = 0; i < keys.length; i++) {
  sum += obj[keys[i]];
}
ready
2
for (var key in obj) {
  sum += obj[key];
}
ready

Revisions

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