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 ObjClosure = function(count) {
var _count = count;
this.next = function() { return ++_count; };
};
var ObjSelfClosure = function(count) {
this._count = count;
var self = this;
this.next = function() { return ++self._count; };
};
var ObjThis = function(count) {
this._count = count;
this.next = function() { return ++this._count; };
};
var _count2 = 0;
var ObjClosure2 = function(count) {
_count2 = count;
this.next = function() { return ++_count2; };
};
var _count3 = 0;
var createObjClosure3 = function(count) {
var dummy = {}; // interm scope content
var ObjClosure3 = function(count) {
this.getDummy = function() { return dummy; };
_count3 = count;
this.next = function() { return ++_count3; };
};
return new ObjClosure3(count);
};
var _count4 = 0;
var createObjClosure4 = function(count) {
var dummyA = {}; // interm scope content
var innerCreateObjClosure4 = function(count) {
var dummyB = {}; // interm scope content
var ObjClosure4 = function(count) {
this.getDummyA = function() { return dummyA; };
this.getDummyB = function() { return dummyB; };
_count4 = count;
this.next = function() { return ++_count4; };
};
return new ObjClosure4(count);
};
return innerCreateObjClosure4(count);
};
var objClosure = new ObjClosure(0);
var objClosureNextFn = objClosure.next;
var objSelfClosure = new ObjSelfClosure(0);
var objSelfClosureNextFn = objSelfClosure.next;
var objThis = new ObjThis(0);
var objThisNextBoundToContext = objThis.next.bind(objThis);
var objClosure2 = new ObjClosure2(0);
var objClosure3 = createObjClosure3(0);
var objClosure4 = createObjClosure4(0);
var objThisNextBoundManually = (function(fn, context) {
return function() {
return fn.apply(context, arguments);
};
})(objThis.next, objThis);
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Access properties via closure |
| ready |
Access properties via self closure |
| ready |
Access properties via this |
| ready |
Access properties via second order closure |
| ready |
Access properties via third order closure |
| ready |
Access properties via fourth order closure |
| ready |
objThis.next.bind(objThis) |
| ready |
objThisNextBoundManually |
| ready |
objClosureNextFn() |
| ready |
objSelfClosureNextFn() |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.