hasOwnProperty vs. the world.

Benchmark created by John-David Dalton on


Description

Tests the performance of using hasOwnProperty in a for-in loop

Preparation HTML

<script>
  var MyObj = !
  function() {
    var i = -1,
        result = {},
        count = +location.hash.slice(2): 50;
    while (++i < count) result[i] = 'x';
    return result;
  }();
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
With hasOwnProperty
for (var i in MyObj) {
  if (MyObj.hasOwnProperty(i)) {}
}
ready
Without
for (var i in MyObj) {}
ready
With hasOwnProperty (100)
for (var i in MyObj100) {
  if (MyObj100.hasOwnProperty(i)) {}
}
ready
Without (100)
for (var i in MyObj100) {}
ready
With hasOwnProperty (1000)
for (var i in MyObj1000) {
  if (MyObj1000.hasOwnProperty(i)) {}
}
ready
Without (1000)
for (var i in MyObj1000) {}
ready

Revisions

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

  • Revision 1: published by John-David Dalton on