prototype vs recreate (v4)

Revision 4 of this benchmark created by Mariusz Nowak on


Description

How speed-wise is relying on prototype

Setup

var Obj = function () {};
  var obj = Obj.prototype = {
    fa: function (a) { return this.fb(a);},
    fb: function (b) { return this.fc(b); },
    fc: function (c) { return c + 1; }
  };
  var cache = [];
  var add2Cache = function (obj) {
    cache.push(obj);
    return obj;
  };

Teardown


    cache = [];
  

Test runner

Ready to run.

Testing in
TestOps/sec
Object.create
add2Cache((function () {
  var o = Object.create(obj);
  return {
    fa: function (a) { return o.fa(a) }
  };
})()).fa(1);
 
ready
Constructor
add2Cache((function () {
  var o = new Obj();
  return {
    fa: function (a) { return o.fa(a) }
  };
})()).fa(2);
ready
Direct
add2Cache((function () {
  var fa = function (a) { return fb(a) }; 
  var fb = function (b) { return fc(b) };
  var fc = function (c) { return c + 1 };

  return {
    fa: fa
  };
}())).fa(3);
ready

Revisions

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