Object keys iteration (v111)

Revision 111 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 < 100; i++) {
  
   data['i' + i] =  { foo: 'bar ' + i, bar: null, baz: 30+i };
  
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
for-in
var keys = Object.keys(data);
var counter = 0;

keys.forEach(function(key) {
   counter += data[key].baz;
)
ready
for-in-cached-hasOwnProperty

var counter = 0;
var key;

for (key in data) {
   counter += data[key].baz
}
ready

Revisions

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