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
Checking the performance of calling public methods with private variables.
<script>
function ConstructorPrivateProperties() {
var privateProperty1 = 1,
privateProperty2 = 2,
privateProperty3 = 3,
privateProperty4 = 4,
privateProperty5 = 5,
privateProperty6 = 6,
privateProperty7 = 7,
privateProperty8 = 8,
privateProperty9 = 9,
privateProperty10 = 10;
this.publicMethod1 = function() {
return privateProperty1 + privateProperty2 + privateProperty3 + privateProperty4 + privateProperty5 + privateProperty6 + privateProperty7 + privateProperty8 + privateProperty9 + privateProperty10;
};
}
function PrototypePrivateProperties() {}
PrototypePrivateProperties.prototype = {
_privateProperty1: 1,
_privateProperty2: 2,
_privateProperty3: 3,
_privateProperty4: 4,
_privateProperty5: 5,
_privateProperty6: 6,
_privateProperty7: 7,
_privateProperty8: 8,
_privateProperty9: 9,
_privateProperty10: 10,
publicMethod1: function() {
return this._privateProperty1 + this._privateProperty2 + this._privateProperty3 + this._privateProperty4 + this._privateProperty5 + this._privateProperty6 + this._privateProperty7 + this._privateProperty8 + this._privateProperty9 + this._privateProperty10;
}
};
// Best practice for use with Google's Closure compiler
function GooglePrivateProperties() {
this._privateProperty1 = 1;
this._privateProperty2 = 2;
this._privateProperty3 = 3;
this._privateProperty4 = 4;
this._privateProperty5 = 5;
this._privateProperty6 = 6;
this._privateProperty7 = 7;
this._privateProperty8 = 8;
this._privateProperty9 = 9;
this._privateProperty10 = 10;
}
GooglePrivateProperties.prototype.publicMethod1 = function() {
return this._privateProperty1 + this._privateProperty2 + this._privateProperty3 + this._privateProperty4 + this._privateProperty5 + this._privateProperty6 + this._privateProperty7 + this._privateProperty8 + this._privateProperty9 + this._privateProperty10;
};
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
call constructor |
| ready |
call prototype |
| ready |
Google Closure style prototype |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.