Object keys iteration (v82)

Revision 82 of this benchmark created by Brian Broll 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] =  { foo: 'bar ' + i, bar: null };
  
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
for-in
for (var key in data) {
  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);

for (var i = 0, len = keys.length; i < len; ++i) {
  data[keys[i]];
}
ready
Inverse loop object keys
var keys = Object.keys(data);

for (var i = keys.length - 1; i >= 0; i--) {
  data[keys[i]];
}
ready
...
var keys = Object.keys(data);

for (var i = keys.length - 1; i >= 0; --i) {
  data[keys[i]];
}
ready
var keys = Object.keys(data);

for (var i = 0, len = keys.length; i < len; i++) {
  data[keys[i]];
}
ready
Concise inverse iteration
var keys = Object.keys(data);

for (var i = keys.length; i--;) {
  data[keys[i]];
}
ready

Revisions

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