Object.keys vs for in w/out hasOwnProperty for values

JavaScript performance comparison

Revision 57 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var obj = {
      foo1: 1401006136982,
      foo2: 1401006136982,
      foo3: 1401006136982,
      foo4: 1401006136982,
      foo5: 1401006136982,
      foo6: 1401006136982,
      foo7: 1401006136982,
      foo8: 1401006136982,
      foo9: 1401006136982,
      foo10: 1401006136982,
      foo11: 1401006136982,
      foo12: 1401006136982,
      foo13: 1401006136982,
      foo14: 1401006136982,
      foo15: 1401006136982,
      foo16: 1401006136982,
      foo17: 1401006136982,
      foo18: 1401006136982,
      foo19: 1401006136982,
      foo20: 1401006136982,
      foo21: 1401006136982,
      foo22: 1401006136982,
      foo23: 1401006136982,
      foo24: 1401006136982,
      foo25: 1401006136982,
      foo26: 1401006136982,
      foo27: 1401006136982,
      foo28: 1401006136982,
      foo29: 1401006136982,
      foo30: 1401006136982,
      foo31: 1401006136982,
      foo32: 1401006136982,
      foo33: 1401006136982,
      foo34: 1401006136982,
      foo35: 1401006136982,
      foo36: 1401006136982,
      foo37: 1401006136982,
      foo38: 1401006136982,
      foo39: 1401006136982,
      foo40: 1401006136982,
      foo41: 1401006136982,
      foo42: 1401006136982,
      foo43: 1401006136982,
      foo44: 1401006136982,
      foo45: 1401006136982,
      foo46: 1401006136982,
      foo47: 1401006136982,
      foo48: 1401006136982,
      foo49: 1401006136982,
      foo50: 1401006136982,
      foo51: 1401006136982,
      foo52: 1401006136982,
      foo53: 1401006136982,
      foo54: 1401006136982,
      foo55: 1401006136982,
      foo56: 1401006136982,
      foo57: 1401006136982,
      foo58: 1401006136982,
      foo59: 1401006136982,
      foo60: 1401006136982,
      foo61: 1401006136982,
      foo62: 1401006136982,
      foo63: 1401006136982,
      foo64: 1401006136982,
      foo65: 1401006136982,
      foo66: 1401006136982,
      foo67: 1401006136982,
      foo68: 1401006136982,
      foo69: 1401006136982,
      foo70: 1401006136982,
      foo71: 1401006136982,
      foo72: 1401006136982,
      foo73: 1401006136982,
      foo74: 1401006136982,
      foo75: 1401006136982,
      foo76: 1401006136982,
      foo77: 1401006136982,
      foo78: 1401006136982,
      foo79: 1401006136982,
      foo80: 1401006136982,
      foo81: 1401006136982,
      foo82: 1401006136982,
      foo83: 1401006136982,
      foo84: 1401006136982,
      foo85: 1401006136982,
      foo86: 1401006136982,
      foo87: 1401006136982,
      foo88: 1401006136982,
      foo89: 1401006136982,
      foo90: 1401006136982,
      foo91: 1401006136982,
      foo92: 1401006136982,
      foo93: 1401006136982,
      foo94: 1401006136982,
      foo95: 1401006136982,
      foo96: 1401006136982,
      foo97: 1401006136982,
      foo98: 1401006136982,
      foo99: 1401006136982
    };
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Object.keys
var keys = Object.keys(obj),
  values = [];
for (var i = 0, m = keys.length; i < m; i++) {
  var prop = keys[i];
  values.push(obj[prop]);
}
pending…
for-in w/out hasOwnProperty
var values = [];
for (var prop in obj) {
  values.push(obj[prop]);
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment