Object keys iteration (v77)

Revision 77 of this benchmark created on


Description

Testing Object.keys vs for-in with lots of small objects.

Preparation HTML

<script>
   var data = {name: 'dave',space:'earth',value:1,bananas:'pajamas',time:'my birthday'};

  function ff(o,h){var i=0,k = Object.keys(o),l = k.length;while(i<l) {h(k[i++]);}}

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
for-in
var copy = {};
for (var key in data) {
   if (data.hasOwnProperty(key)) {
      copy[key] = data[key];
   }
}
ready
object-keys
var copy = {};
ff(data,function(key){copy[key]=data[key];});
ready
object-keys 2
var keys = Object.keys(data);
var len = keys.length;
var i = 0;
var copy = {};
while (i < len) {
   copy[keys[i]] = data[keys[i]];
   i++;
}
ready
object-keys 3
var keys = Object.keys(data);
var len = keys.length;
var i;
var copy = {};
for (i = 0; i < len; i++) {
  copy[keys[i]] = data[keys[i]];
}
ready

Revisions

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