Shared non-primitive objects.

Benchmark created on


Description

Non-primitive objects defined on the prototype are shared and result in much higher speed.

Setup

function Size(width, height) {
            this.width = width;
            this.height = height;
        };
    
    
        Size.prototype.area = function() {
           return this.width * this.height;
        };
    
        function Size2(width, height) {
           this.width = width;
           this.height = height;
           this.area = function() {
              return this.width * this.height;
           }
        }

Test runner

Ready to run.

Testing in
TestOps/sec
Prototype definition
    var s = new Size(5, 10);
   
ready
Instance definition
 var s2 = new Size2(5, 10);
ready

Revisions

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