Object keys iteration (v113)

Revision 113 of this benchmark created on


Description

Testing Object.keys vs for-in. I see that SlickGrid uses objects with indexed keys rather than arrays. Confused....

Preparation HTML

<script>
  var data = {};
  
  for (var i = 0; i < 100; i++) {
  
   data[i] =  i;
  
  }
</script>

Test runner

Ready to run.

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

for (i = 0; i < len; ++i) {
  sum += data[keys[i]];
}
ready

Revisions

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