Object keys iteration (v51)

Revision 51 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 = Object.create(null);
  var out = {};
  
  for (var i = 0; i < 100000; i++) {
   var key = 'user ' + i;
   data[key] =  key + i;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
for-in
for (var key in data) {
  if (key.indexOf("d") == 0) {
    out[key] = data[key];
  }
}
ready
object-keys-foreach
Object.keys(data).forEach(function(key) {
  if (key.indexOf("d") == 0) {
    out[key] = data[key];
  }
});
ready
object-keys
var keys = Object.keys(data);

for (var i = 0; i < keys.length; i++) {
  var key = keys[i];
  if (key.indexOf("d") == 0) {
    out[key] = data[key];
  }
}
ready
object.getownpropertynames
var keys = Object.getOwnPropertyNames(data);

for (var i = 0; i < keys.length; i++) {
  var key = keys[i];
  if (key.indexOf("d") == 0) {
    out[key] = data[key];
  }
}
ready

Revisions

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