Object keys iteration (v60)

Revision 60 of this benchmark created by Jimb Esser on


Description

Testing Object.keys vs for-in.

Preparation HTML

<script>
  var data = {};
  
  for (var i = 0; i < 100; i++) {
  
   data['a' + i] =  { foo: 'bar ' + i, bar: null };
  
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
for-in
for (var key in data) {
  if (Object.prototype.hasOwnProperty.call(data, key)) {
    data[key];
  }
}
ready
for-in-cached-hasOwnProperty
var ownProp = Object.prototype.hasOwnProperty;
for (var key in data) {
  if (ownProp.call(data, key)) {
    data[key];
  }
}
ready
for-in-no-hasOwnProperty
for (var key in data) {
  data[key];
}
ready
object-keys 3
var keys = Object.keys(data);
var len = keys.length;
var i;

for (i = 0; i < len; ++i) {
  data[keys[i]];
}
ready
for-in-var-defined-out-of-loop
var key;
for (key in data) {
    data[key];
}
ready

Revisions

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