Object keys iteration (v35)

Revision 35 of this benchmark created by gfgfg 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 = {
1 : 1,
2 : 1,
5 : 1,
10 : 1,
11 : 1,
15 : 1
};
  var out = {};
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
for-in
for (var key in data) {
  out[key] = data[key];
}
ready
object-keys-foreach
Object.keys(data).forEach(function(key) {
  out[key] = data[key];
});
ready
object-keys
var keys = Object.keys(data);

for (var i = 0; i < keys.length; i++) {
  var key = keys[i];
  out[key] = data[key];
}
ready
object.getownpropertynames
var keys = Object.getOwnPropertyNames(data);

for (var i = 0; i < keys.length; i++) {
  var key = keys[i];
  out[key] = data[key];
}
ready
array iteration
for (var i = 0; i < 20; i++) {
  if (data[i]) {
    out[i] = data[i];
  }
}
ready

Revisions

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