Object keys iteration (v99)

Revision 99 of this benchmark created on


Description

Testing Object.keys vs for-in. I've added jQuery's .each() for my own testing.

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

var data = {};
    var data_copy = {};
      
      for (var k = 0; k < 750; k+=1) {
      if (k<500) {
       data[k] =  'user ' + k;
     } else {
       data[k] = undefined;
     }
      
      }
    
    var keys = Object.keys(data);
    var len = keys.length;
    var i = 0;
    var prop;

Test runner

Ready to run.

Testing in
TestOps/sec
for-in
while (i < len) {
  prop = keys[i];
  data_copy[prop] = data[prop];
  i+=1;
}
ready
object-keys
while (i < len) {
  prop = keys[i];
  data_copy[prop] = data[prop];
  i++;
}
ready
object-keys 2
while (len) {
  prop = keys[len];
  data_copy[prop] = data[prop];
  len-=1;
}
ready
object-keys 3
while (len) {
  prop = keys[len];
  data_copy[prop] = data[prop];
  len--;
}
ready

Revisions

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