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
var array = Array(10000).join('x').split('');
function callback(value, index, object) {
return value + index;
}
function customForEach(array, callback, thisArg) {
var len = array.length;
for (var i = 0; i<len; i++) {
callback.call(thisArg, array[i], i, array);
}
}
Array.prototype.forEach1 = function(fn, scope) {
for(var i = 0, len = this.length; i < len; ++i) {
fn.call(scope, this[i], i, this);
}
}
Array.prototype.forEach2 = function( callback, thisArg ) {
var T, k;
if ( this == null ) {
throw new TypeError( "this is null or not defined" );
}
var O = Object(this);
var len = O.length >>> 0; // Hack to convert O.length to a UInt32
if ( {}.toString.call(callback) !== "[object Function]" ) {
throw new TypeError( callback + " is not a function" );
}
if ( typeof thisArg !== 'undefined' ) {
T = thisArg;
}
k = 0;
while( k < len ) {
var kValue;
if ( Object.prototype.hasOwnProperty.call(O, k) ) {
kValue = O[ k ];
callback.call( T, kValue, k, O );
}
k++;
}
};
Array.prototype.forEach3 = function(callback, thisArg)
{
var fn = callback,
index = -1,
length = this.length;
while (++index < length) {
if (callback(this[index], index, this) === false) {
break;
}
}
return this;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Custom /Function |
| ready |
Native |
| ready |
Compatibility/Shim |
| ready |
ECMA-262/Shim |
| ready |
Custom/Prototype |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.