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 SAFE_MODE = 0
function EMPTY(args){
return SAFE_MODE ? [] : Array(args.length)
}
function arrayProtoSlice() {
return Array.prototype.slice.apply(arguments);
}
function arrayProtoSliceExceptOne() {
return Array.prototype.slice.call(arguments,1);
}
function arrayProtoSliceExceptMany(many) {
return Array.prototype.slice.call(arguments,many);
}
function arrayLiteralSlice() {
return EMPTY(arguments).slice.apply(arguments);
}
function arrayLiteralSliceExceptOne() {
return [].slice.call(arguments,1);
}
function arrayLiteralSliceExceptMany(many) {
return [].slice.call(arguments,many);
}
var _slice = [].slice;
function closureSlice() {
return _slice.call(arguments);
}
function closureSliceExceptOne() {
return _slice.call(arguments,1);
}
function closureSliceExceptMany(many) {
return _slice.call(arguments,many);
}
var _splice = [].splice;
function closureSplice() {
return _splice.call(arguments);
}
function closureSpliceExceptOne() {
return _splice.call(arguments,1);
}
function closureSpliceExceptMany(many) {
return _splice.call(arguments,many);
}
function slice() {
return [].splice.call(arguments, 0);
}
function sliceExceptOne() {
return [].splice.call(arguments, 1);
}
function sliceExceptMany(many) {
return [].splice.call(arguments, many);
}
function splice() {
return [].splice.call(arguments, 0);
}
function spliceExceptOne() {
return [].splice.call(arguments, 1);
}
function spliceExceptMany(many) {
return [].splice.call(arguments, many);
}
function push() {
var x = [];
x.push.apply(x, arguments);
return x;
}
function pushLoop() {
var x = [], len= arguments.length;
for(var i= 0; i< len; ++i)
x.push(arguments[i])
return x;
}
function pushLoopExceptOne() {
var x = [], len= arguments.length;
for(var i= 1; i< len; ++i)
x.push(arguments[i])
return x;
}
function pushLoopExceptMany(many) {
var x = [], len= arguments.length;
for(var i= many; i< len; ++i)
x.push(arguments[i])
return x;
}
function unshift() {
var x = [];
x.unshift.apply(x, arguments);
return x;
}
function unshiftExceptOne() {
var x = [];
x.unshift.apply(x, arguments);
x.shift();
return x;
}
function unshiftExceptMany(many) {
var x = [];
x.unshift.apply(x, arguments);
x= x.splice(many)
return x;
}
function whileDecPostfix() {
var arr = EMPTY(arguments),
i = arguments.length;
while (i--) {
arr[i] = arguments[i];
}
return arr;
}
function whileDecPostfixExceptOne() {
var arr = EMPTY(arguments),
i = arguments.length-1;
while (i) {
arr[i] = arguments[--i];
}
return arr;
}
function whileDecPostfixExceptMany(many) {
var arr = EMPTY(arguments),
i = arguments.length,
j = arguments.length - many;
while (j > 0) {
arr[--j] = arguments[--i]
}
return arr;
}
function whileInc() {
var arr = EMPTY(arguments),
i = 0,
len = arguments.length;
while (++i <= len) {
arr[i] = arguments[i];
}
return arr;
}
function whileIncExceptOne() {
var arr = [],
i = 0,
j,
len = arguments.length;
while ((j = i++) <= len) {
arr[j] = arguments[i];
}
return arr;
}
function whileIncExceptMany(many) {
var arr = [],
i = many-1,
j = -1,
len = arguments.length;
while (i < len) {
arr[++j] = arguments[++i];
}
return arr;
}
function byConstructor() {
return Array.apply(Array, arguments);
}
var bigArray = new Array(1001).join("a").split("");
var smallArray = new Array(6).join("a").split("");
var manyArray = new Array(1001+44).join("a").split(""), many = 88;
manyArray.unshift(many);
var smallManyArray = new Array(7).join("a").split("");
smallManyArray.unshift(1);
SAFE_MODE = 0;
arrayProtoSlice.apply(null, bigArray).length === bigArray.length || alert('arrayProtoSlice broken');
arrayProtoSliceExceptOne.apply(null, bigArray).length + 1 === bigArray.length || alert('arrayProtoSliceExceptOne broken');
arrayProtoSliceExceptMany.apply(null, manyArray).length + many === bigArray.length || alert('arrayProtoSliceExceptMany broken');
arrayLiteralSlice.apply(null, bigArray).length === bigArray.length || alert('arrayLiteralSlice broken');
arrayLiteralSliceExceptOne.apply(null, bigArray).length + 1 === bigArray.length || alert('arrayLiteralSliceExceptOne broken');
arrayLiteralSliceExceptMany.apply(null, manyArray).length + many === bigArray.length || alert('arrayLiteralSliceExceptMany broken');
closureSlice.apply(null, bigArray).length === bigArray.length || alert('closureSlice broken');
closureSliceExceptOne.apply(null, bigArray).length + 1 === bigArray.length || alert('closureSliceExceptOne broken');
closureSliceExceptMany.apply(null, manyArray).length + many === bigArray.length || alert('closureSliceExceptMany broken');
closureSplice.apply(null, bigArray).length === bigArray.length || alert('closureSplice broken');
closureSpliceExceptOne.apply(null, bigArray).length + 1 === bigArray.length || alert('closureSpliceExceptOne broken');
closureSpliceExceptMany.apply(null, manyArray).length + many === bigArray.length || alert('closureSpliceExceptMany broken');
slice.apply(null, bigArray).length === bigArray.length || alert('slice broken');
sliceExceptOne.apply(null, bigArray).length + 1 === bigArray.length || alert('sliceExceptOne broken');
sliceExceptMany.apply(null, manyArray).length + many === bigArray.length || alert('sliceExceptMany broken');
splice.apply(null, bigArray).length === bigArray.length || alert('splice broken');
spliceExceptOne.apply(null, bigArray).length + 1 === bigArray.length || alert('spliceExceptOne broken');
spliceExceptMany.apply(null, manyArray).length + many === bigArray.length || alert('spliceExceptMany broken');
push.apply(null, bigArray).length === bigArray.length || alert('push broken');
pushLoop.apply(null, bigArray).length === bigArray.length || alert('pushLoop broken');
pushLoopExceptOne.apply(null, bigArray).length + 1 === bigArray.length || alert('pushLoopExceptOne broken');
pushLoopExceptMany.apply(null, manyArray).length + many === bigArray.length || alert('pushLoopExceptMany broken');
unshift.apply(null, bigArray).length === bigArray.length || alert('unshift broken');
unshiftExceptOne.apply(null, bigArray).length + 1 === bigArray.length || alert('unshiftExceptOne broken');
unshiftExceptMany.apply(null, manyArray).length + many === bigArray.length || alert('unshiftExceptMany broken');
whileDecPostfix.apply(null, bigArray).length === bigArray.length || alert('whileDecPostfix broken');
whileDecPostfixExceptOne.apply(null, bigArray).length + 1 === bigArray.length || alert('whileDecPostfixExceptOne broken');
whileDecPostfixExceptMany.apply(null, manyArray).length + many === bigArray.length || alert('whileDecPostfixExceptMany broken');
whileInc.apply(null, bigArray).length === bigArray.length || alert('whileInc broken');
whileIncExceptOne.apply(null, bigArray).length + 1 === bigArray.length || alert('whileIncExceptOne broken');
whileIncExceptMany.apply(null, manyArray).length + many === bigArray.length || alert('whileIncExceptMany broken');
byConstructor.apply(null, bigArray).length === bigArray.length || alert('byConstructor broken');
if(console && console.log) console.log("gtg")
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Array prototype slice |
| ready |
Array literal slice |
| ready |
Array push |
| ready |
Array splice |
| ready |
Unshift |
| ready |
Closure |
| ready |
While loop |
| ready |
Constructor loop |
| ready |
arrayProtoSliceExceptOne |
| ready |
arrayProtoSliceExceptMany |
| ready |
arrayLiteralSliceExceptOne |
| ready |
arrayLiteralSliceExceptMany |
| ready |
closureSliceExceptOne |
| ready |
closureSliceExceptMany |
| ready |
closureSplice |
| ready |
closureSpliceExceptOne |
| ready |
closureSpliceExceptMany |
| ready |
slice |
| ready |
sliceExceptOne |
| ready |
sliceExceptMany |
| ready |
spliceExceptOne |
| ready |
pushLoop |
| ready |
pushLoopExceptOne |
| ready |
pushLoopExceptMany |
| ready |
unshiftExceptOne |
| ready |
unshiftExceptMany |
| ready |
whileDecPostfix |
| ready |
whileDecPostfixExceptOne |
| ready |
whileDecPostfixExceptMany |
| ready |
whileInc |
| ready |
whileIncExceptOne |
| ready |
whileIncExceptMany |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.