Object keys iteration (v53)

Revision 53 of this benchmark created on


Description

Proving a point about obj.hasOwnProperty

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  var data = {};
  var out = {};
  
  for (var i = 0; i < 100000; i++) {
   var key = 'user ' + i;
   data[key] =  key + i;
  }
</script>

Test runner

Ready to run.

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

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

for (var i = 0; i < keys.length; i++) {
  var key = keys[i];
  if (key.indexOf("d") == 0) {
    out[key] = data[key];
  }
}
ready
$.each
$.each(data, function(key, val) {
  if (key.indexOf("d") == 0) {
    out[key] = val;
  }
});
ready
for-in-has
for (var key in data) {
  if (data.hasOwnProperty(key)) {
      if (key.indexOf("d") == 0) {
        out[key] = data[key];
      }
    }
  }
ready

Revisions

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