Object keys iteration (v95)

Revision 95 of this benchmark created by Fabio Costa on


Description

Testing Object.keys vs for-in. I see that SlickGrid uses objects with indexed keys rather than arrays. Confused....

Setup

var X = function() {
      this.x = 1;
      this.y = 4;
    };
    var data = [
    {foo: 'bar', bar: null, d: 3, f: 20, g: 30},
    {bar: null, 12312312: 30},
    new X(),
    {bar: null, 12312312: 30},
    new X(),
    {foo: 'bar', bar: null, d: 3, f: 20, g: 30}
    ];
    var ownProp = Object.prototype.hasOwnProperty;

Test runner

Ready to run.

Testing in
TestOps/sec
for-in
for (var y = 0; y < data.length; y++) {
  var _data = data[y];
  for (var key in _data) {
    if (ownProp.call(data, key)) {
      data[key];
    }
  }
}
ready
object.keys
for (var y = 0; y < data.length; y++) {
  var keys = Object.keys(data[y]);
  for (var i = 0, len = keys.length; i < len; ++i) {
    data[keys[i]];
  }
}
ready

Revisions

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