Object keys iteration (v74)

Revision 74 of this benchmark created by Dave 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'};
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
for-in
var copy = {};
for (var key in data) {
   copy[key] = data[key];
}
ready
object-keys
var copy = {};
Object.keys(data).forEach(function(element, index, array){
  copy[element] = data[element];
});
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.