Object keys iteration (v65)

Revision 65 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 < 10000; i++) {
  
   data[i] =  'user ' + i;
  
  }
</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);
var len = keys.length;
var i = 0;

while (i < len) {
   data[keys[i]];
   i++;
}
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
foreach
Object.prototype.foreach=function foreach(f2){
        var keys=Object.keys(this);
        for(var i=0,l=keys.length;i<l;i++){
                f2(keys[i],this[keys[i]]);
        }
};
data.foreach(function(key,item){});
ready
f2
data.foreach=function foreach(f2){
        var keys=Object.keys(this);
        for(var i=0,l=keys.length;i<l;i++){
                f2(keys[i],this[keys[i]]);
        }
};
data.foreach(function(key,item){});
ready
f2
Object.prototype.foreach=function foreach(f2){
        var keys=Object.keys(this);
        
  for(var i=0,l=keys.length;i<l;i++){
                f2(this[keys[i]]);
        }
};
data.foreach(function(item){});
ready

Revisions

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