hasOwnProperty call vs. direct (v8)

Revision 8 of this benchmark created on


Description

Is it faster to call hasOwnProperty directly or via call? How much faster?

Preparation HTML

<script>
  var hash = {
   a: 1,
   b: 2,
   c: 3,
   d: 4,
   e: 5,
   f: 6
  };
  var keys = [ "a", "b", "c", "d", "e", "f" ];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
hasOwnProperty via call
for (var key in hash) {
 if (Object.prototype.hasOwnProperty.call(hash, key)) {
  hash[key] * 5;
 }
}
ready
in
for (var key in hash) {
 if (hash.hasOwnProperty(key)) {
  hash[key] * 5;
 }
}
ready
cache method via call
var hasOwnProp = Object.prototype.hasOwnProperty;
for (var key in hash) {
 if (hasOwnProp.call(hash, key)) {
  hash[key] * 5;
 }
}
ready
fuck hasOwnProperty?
for (var key in hash) {
  hash[key] * 5;
}
ready
{}
var  o = {};
for (var key in hash) {
  if(!o[key]){
  hash[key] * 5;}
}
ready
var  o = {};
for (var key in hash) {
  if(o[key] !== hash[key]){
  hash[key] * 5;}
}
ready
Iterate over keys list
for (var i = 0; i < keys.length; i++) {
  hash[keys[i]] * 5;
}
 
ready

Revisions

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