For..in loop with and without hasOwnProperty (v2)

Revision 2 of this benchmark created on


Description

Showing the performance difference between a for..in loop using hasOwnProperty and without.

Setup

var obj = {
        somekey: 'somevalue',
        somekey2: 'somevalue',
        somekey3: 'somevalue'
    };

Test runner

Ready to run.

Testing in
TestOps/sec
For..in without hasOwnProperty check
for (var val in obj) {
    console.log(val);
}
ready
For..in with hasOwnProperty check
for (var val in obj) {
    if (obj.hasOwnProperty(val)) {
        console.log(val);
    }
}
ready
Reverse While Loop
var i = obj.length;

while(i--){
    console.log(obj[i]);
}
ready
While Loop Incremented
var l = obj.length;
var i = 0;

while (i < l) {
  console.log(obj[i]);
  i += 1;
}
ready

Revisions

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