jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
<script>
var ClassA = function(state) {
this.state = state;
};
ClassA.prototype = {
publicMethod1: function(x) {
return this.state == 'foo' && this.publicMethod2(x);
},
publicMethod2: function(x) {
return this.state == 'foo' && this.publicMethod3(x);
},
publicMethod3: function(x) {
return this.state == 'foo' && this.publicMethod4(x);
},
publicMethod4: function(x) {
return this.state == x;
}
};
var ClassB = function(state) {
function privateMethod1(x) {
return state == 'foo' && privateMethod2(x);
};
function privateMethod2(x) {
return state == 'foo' && privateMethod3(x);
};
function privateMethod3(x) {
return state == 'foo' && privateMethod4(x);
};
function privateMethod4(x) {
return state == x;
};
this.publicMethod1 = privateMethod1;
this.publicMethod2 = privateMethod2;
this.publicMethod3 = privateMethod3;
this.publicMethod4 = privateMethod4;
};
var ClassC = function(state) {
this.state = state;
};
ClassC.prototype = (function() {
function privateMethod1(x) {
return this.state == 'foo' && privateMethod2.call(this, x);
};
function privateMethod2(x) {
return this.state == 'foo' && privateMethod3.call(this, x);
};
function privateMethod3(x) {
return this.state == 'foo' && privateMethod4.call(this, x);
};
function privateMethod4(x) {
return this.state == x;
};
return {
publicMethod1: privateMethod1,
publicMethod2: privateMethod2,
publicMethod3: privateMethod3,
publicMethod4: privateMethod4
};
})();
var ClassD = function(state) {
this.state = state;
};
ClassD.prototype = (function() {
function privateMethod1(self, x) {
return self.state == 'foo' && privateMethod2(self, x);
};
function privateMethod2(self, x) {
return self.state == 'foo' && privateMethod3(self, x);
};
function privateMethod3(self, x) {
return self.state == 'foo' && privateMethod4(self, x);
};
function privateMethod4(self, x) {
return self.state == x;
};
return {
publicMethod1: function(x) {
return privateMethod1(this, x);
},
publicMethod2: function(x) {
return privateMethod2(this, x);
},
publicMethod3: function(x) {
return privateMethod3(this, x);
},
publicMethod4: function(x) {
return privateMethod4(this, x);
}
};
})();
var ClassE = function(state) {
this.state = state;
};
ClassE.prototype = (function() {
var state;
function privateMethod1(x) {
return state == 'foo' && privateMethod2(x);
};
function privateMethod2(x) {
return state == 'foo' && privateMethod3(x);
};
function privateMethod3(x) {
return state == 'foo' && privateMethod4(x);
};
function privateMethod4(x) {
return state == x;
};
return {
publicMethod1: function(x) {
var stack = state;
state = this.state;
var result = privateMethod1(x);
state = stack;
return result;
},
publicMethod2: function(x) {
var stack = state;
state = this.state;
var result = privateMethod2(x);
state = stack;
return result;
},
publicMethod3: function(x) {
var stack = state;
state = this.state;
var result = privateMethod3(x);
state = stack;
return result;
},
publicMethod4: function(x) {
var stack = state;
state = this.state;
var result = privateMethod4(x);
state = stack;
return result;
}
};
})();
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Plain prototype |
| ready |
Closure |
| ready |
Prototype + Internal call |
| ready |
Prototype + Internal self argument |
| ready |
Prototype + Internal self state |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.