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
These work exactly the same as the native array functions, just without the type checking. Possibly because of the lack of type checking, these implementations are significantly faster than the native ones.
Array.prototype._forEach = function(cb, thisArg) {
var len = this.length;
for (var i = 0; i < len; i++) {
var result = cb.call(thisArg, this[i], i, this);
if (typeof result !== 'undefined' && !result) break;
}
}
Array.prototype._forEachRight = function(cb, thisArg) {
var len = this.length;
for (var i = len - 1; i >= 0; i--) {
var result = cb.call(thisArg, this[i], i, this);
if (typeof result !== 'undefined' && !result) break;
}
}
Array.prototype._map = function(cb, thisArg) {
var arr = new Array(this.length);
this._forEach(function(e, i, t) {
arr[i] = cb(e, i, t);
return true;
}, thisArg);
return arr;
}
Array.prototype._reduce = function(cb, initial) {
this._forEach(function(e, i, t) {
initial = cb(initial, e, i, t);
return true;
});
return initial;
}
Array.prototype._reduceRight = function(cb, initial) {
this._forEachRight(function(e, i, t) {
initial = cb(initial, e, i, t);
return true;
});
}
Array.prototype._every = function(cb, thisArg) {
var condition = true;
this._forEach(function(e, i, t) {
condition = !! cb(e, i, t);
return condition;
}, thisArg);
return condition;
}
Array.prototype._some = function(cb, thisArg) {
var condition = false;
this._forEach(function(e, i, t) {
condition = !! cb(e, i, t);
return !condition;
}, thisArg);
return condition;
}
Array.prototype._filter = function(cb, thisArg) {
var arr = [];
this._forEach(function(e, i, t) {
if (cb(e, i, t)) arr.push(e);
return true;
}, thisArg);
return arr;
}
var arr = new Array(1000);
for (var i = 0; i < arr.length; i++){arr[i] = i;}
Ready to run.
Test | Ops/sec | |
---|---|---|
Homemade _forEach |
| ready |
Native forEach |
| ready |
Homemade _map |
| ready |
Native map |
| ready |
Homemade _reduce |
| ready |
Native reduce |
| ready |
Homemade _reduceRight |
| ready |
Native reduceRight |
| ready |
Homemade _every |
| ready |
Native every |
| ready |
Homemade _some |
| ready |
Native some |
| ready |
Homemade _filter |
| ready |
Native filter |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.