Object Keys Vs For In (v7)

Revision 7 of this benchmark created by my name on


Setup

var jsonObj = {
      prop1: "abc",
      prop2: "def",
      prop3: "ghi",
      prop4: "jkl",
      prop5: "mno",
      prop6: "pqr",
      prop7: "stu",
      prop8: "vwx",
      prop9: "yz",
      prop10: "abc",
      prop11: "abc",
      prop12: "def",
      prop13: "ghi",
      prop14: "jkl",
      prop15: "mno",
      prop16: "pqr",
      prop17: "stu",
      prop18: "vwx",
      prop19: "yz",
      prop20: "yz",
      prop21: "abc",
      prop22: "def",
      prop23: "ghi",
      prop24: "jkl",
      prop25: "mno",
      prop26: "pqr",
      prop27: "stu",
      prop28: "vwx",
      prop29: "yz",
      prop31: "abc",
      prop32: "def",
      prop33: "ghi",
      prop34: "jkl",
      prop35: "mno",
      prop36: "pqr",
      prop37: "stu",
      prop38: "vwx",
      prop39: "yz",
      prop41: "abc",
      prop42: "def",
      prop43: "ghi",
      prop44: "jkl",
      prop45: "mno",
      prop46: "pqr",
      prop47: "stu",
      prop48: "vwx",
      prop49: "yz",
      prop51: "abc",
      prop52: "def",
      prop53: "ghi",
      prop54: "jkl",
      prop55: "mno",
      prop56: "pqr",
      prop57: "stu",
      prop58: "vwx",
      prop59: "yz",
      prop61: "abc",
      prop62: "def",
      prop63: "ghi",
      prop64: "jkl",
      prop65: "mno",
      prop66: "pqr",
      prop67: "stu",
      prop68: "vwx",
      prop69: "yz"
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Object.keys
var result = "";
Object.keys(jsonObj).forEach(function(key) {
  result = result + jsonObj[key];
});
ready
For In
var result = "";
for (key in jsonObj) {
  if (jsonObj.hasOwnProperty(key)) {
    result = result + jsonObj[key];
  }
}
ready
Object.keys for loop
var result = "",
  keys = Object.keys(jsonObj);

for (var i = 0, l = keys.length; i < l; i++) {
  result = result + jsonObj[keys[i]];
}
ready
For In No HasOwnProperty
var result = "";
for (key in jsonObj) {
  result = result + jsonObj[key];
}
ready

Revisions

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