Object keys iteration (v22)

Revision 22 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>


window.keys = Object.keys
window.ownp = Object.prototype.hasOwnProperty

window.count = function(){return 200000};
window.data = {};
for (var remain = count(); remain; --remain) {
 data[remain] = 1;
}

window.minObject = {'solo': 'all alone'};
window.decVar = 10000000;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Simple For-In
for (var k in data) {
  data[k];
}
ready
w/ Own Property Check
for (var k in data) {
  if ( ownp.call(data, k) ) {
    data[k];
  }
}
ready
Using Object Keys (For)
var k=keys(data)
   ,l=k.length-1
   ;
for (l; l; l) {
  data[k[--l]];
}
ready
Using Object Keys (While)
var k=keys(data);
var l=k.length;
while(l) {
  data[k[--l]];
}
ready
Min Time to get Keys
keys(minObject);
ready
Min Time to Initialize Loop
var l = 1
   ;
for ( l; l; l ){
--l
};
ready
Min Time to Initialize While
var l = 1
   ;
while ( l ){
--l
};
ready
Time to Get More Keys
var k=keys(data);
ready
Time to Do For Loop
var l = window.count()
   ;
for ( l; l; l ){
--l
};
ready
Time to Do While Loop
var l = window.count()
   ;
while( l ){
--l
};
ready
Time to Decrement
--decVar;
ready
Initialize a Variable
var v;
ready
Init and Set a Variable
var v = 0;
ready
Assume Dense Numerically Indexed Obj
var l = window.count()
   ;
while( l ){
data[--l]
};
ready

Revisions

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