Object keys iteration (v5)

Revision 5 of this benchmark created by Michael Jostmeyer 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 < 10000; i++) {
  
   data['xyz_'+i] =  'user ' + i;
   data['abc_'+i] = function(){};
  
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
for-in
for (var key in data) {
   data[key];
}
ready
object-keys
Object.keys(data).forEach(function(element, index, array){
  data[element];
});
ready
object-keys 2
var keys = Object.keys(data),
    len = keys.length;

while (len--) {
   data[keys[len]];
   i++;
}
ready
object-keys 3
var keys = Object.keys(data), len = keys.length, i=0;

for (; i < len;) {
  data[keys[i++]];
}
ready
for-in (filtered)
for (var key in data) {
   if(data.hasOwnProperty(key)){
      data[key];
   }
}
ready
for-in without functions 1
var key, value;
for (key in data) {
   value = data[key];
   if(typeof value !== 'function' && data.hasOwnProperty(key)){
      value;
   }
}
ready
for-in without functions 2
var key, value;
for (key in data) {
   value = data[key];
   if(typeof value !== 'function'){
      value;
   }
}
ready

Revisions

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