prototype vs recreate (v2)

Revision 2 of this benchmark created on


Description

How speed-wise is relying on prototype

Preparation HTML

<script>
  var Obj = function () {};
  var obj = Obj.prototype = {
    method1: function (a) { return a;},
    method2: function (b) { return b + 1; },
    method3: function (c) { return true; }
  };
  var cache = [];
  var add2Cache = function (obj) {
    cache.push(obj);
    return obj;
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Direct
add2Cache({
  method1: function (a) { return a;},
  method2: function (b) { return b + 1; },
  method3: function (c) { return true; }
}).method1(2);
ready
Constructor
add2Cache(new Obj()).method1(1);
ready
Object.create
add2Cache(Object.create(obj)).method1(1);
ready

Revisions

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