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) {
for (var i = 0; i < 1000; i++)
if (this.publicMethod2(x, i)) return true;
return false;
},
publicMethod2: function(x, i) {
return this.state == x + i;
}
};
var ClassB = function(state) {
function privateMethod1(x) {
for (var i = 0; i < 1000; i++)
if (privateMethod2(x, i)) return true;
return false;
};
function privateMethod2(x, i) {
return state == x + i;
};
this.publicMethod1 = privateMethod1;
this.publicMethod2 = privateMethod2;
};
var ClassC = function(state) {
this.state = state;
};
ClassC.prototype = (function() {
function privateMethod1(x) {
for (var i = 0; i < 1000; i++)
if (privateMethod2.call(this, x, i)) return true;
return false;
};
function privateMethod2(x, i) {
return this.state == x + i;
};
return {
publicMethod1: privateMethod1,
publicMethod2: privateMethod2
};
})();
var ClassD = function(state) {
this.state = state;
};
ClassD.prototype = (function() {
function privateMethod1(self, x) {
for (var i = 0; i < 1000; i++)
if (privateMethod2(self, x, i)) return true;
return false;
};
function privateMethod2(self, x, i) {
return self.state == x + i;
};
return {
publicMethod1: function(x) {
return privateMethod1(this, x);
},
publicMethod2: function(x, i) {
return privateMethod2(this, x, i);
}
};
})();
var ClassE = function(state) {
this.state = state;
};
ClassE.prototype = (function() {
var state;
function privateMethod1(x) {
for (var i = 0; i < 1000; i++)
if (privateMethod2(x, i)) return true;
return false;
};
function privateMethod2(x, i) {
return state == x + i;
};
return {
publicMethod1: function(x) {
var stack = state;
state = this.state;
var result = privateMethod1(x);
state = stack;
return result;
},
publicMethod2: function(x, i) {
var stack = state;
state = this.state;
var result = privateMethod2(x, i);
state = stack;
return result;
}
};
})();
var instA = new ClassA(10);
var instB = new ClassB(10);
var instC = new ClassC(10);
var instD = new ClassD(10);
var instE = new ClassE(10);
</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.