for-in-vs-es5

Benchmark created by John-David Dalton on


Setup

function forInES5(object, iterator) {
      var keys, key;
      do {
        keys = Object.keys(object);
        while ((key = keys.shift()) != null) {
          iterator(object[key], key, object);
        }
      } while ((object = Object.getPrototypeOf(object)));
    }
    
    function forInOld(object, iterator) {
      for (var key in object) {
        if (object.hasOwnProperty(key)) {
          iterator(object[key], key, object);
        }
      }
    }
    
    function GrandParent() { }
    function Parent() { }
    Parent.prototype = Object.create(GrandParent.prototype);
    function Child() { }
    Child.prototype = Object.create(Parent.prototype);
    
    var kid = new Child;
    kid.name = 'timmy';
    kid.age = '10';
    
    function callback() { }

Test runner

Ready to run.

Testing in
TestOps/sec
ES5
forInES5(kid, callback);
ready
Old
forInOld(kid, callback);
ready

Revisions

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

  • Revision 1: published by John-David Dalton on