Object keys iteration

JavaScript performance comparison

Revision 22 of this test case created

Info

Testing Object.keys vs for-in. I see that SlickGrid uses objects with indexed keys rather than arrays. Confused....

Preparation code

<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

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

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

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment