object literal iteration (v5)

Revision 5 of this benchmark created by Pencroff on


Setup

var obj = {};
  for (var i = 0; i < 10000; i++) {
    obj['key' + i] = 'value' + i;
  }
  
  var res = [];

Teardown



            res = [];
        
  

Test runner

Ready to run.

Testing in
TestOps/sec
forEach in Obj.keys()
// In ECMA5 Object.key(obj) returns only iterable props in the object 
// that pass obj.hasOwnProperty

Object.keys(obj).forEach(function(key) {
  res.push(obj[key]);
});
ready
prop in obj
for (var prop in obj) {
  if (obj.hasOwnProperty(prop)) {
    res.push(obj[prop]);
  }
}
ready
prop in Obj.keys()
// In ECMA5 Object.key(obj) returns only iterable props in the object 
// that pass obj.hasOwnProperty

for (var prop in Object.keys(obj)) {
  res.push(obj[prop]);
}
ready
for loop Obj.keys()
var keys = Object.keys(obj);
for (var i = 0; i < keys.length; i++) {
  res.push(obj[keys[i]]);
}
ready
Obj.key forEach bind
// In ECMA5 Object.key(obj) returns only iterable props in the object 
// that pass obj.hasOwnProperty

Object.keys(obj).forEach(function(key) {
  res.push(obj[key]);
}.bind(this));
ready
prop in obj no hasOwnProperty
for (var prop in obj) {
  res.push(obj[prop]);
}
ready

Revisions

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