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
function noConstVar(arr, add){
const addSize = add.length;
if (addSize === 0) {
return;
}
const baseSize = arr.length;
arr.length = baseSize + addSize;
for (let i = 0; i < addSize; i++) {
arr[baseSize + i] = add[i];
}
}
function withConstVar(arr, add){
const addSize = add.length;
if (addSize === 0) {
return;
}
const baseSize = arr.length;
arr.length = baseSize + addSize;
for (let i = 0; i < addSize; i++) {
const element = add[i]
arr[baseSize + i] = element;
}
}
function addFromBehind(arr, add){
const addSize = add.length;
if (addSize === 0) {
return;
}
const baseSize = arr.length;
arr.length = baseSize + addSize;
const totalSize = baseSize + addSize;
const maxIndex = totalSize - 1;
let t = 0;
for (let i = addSize - 1; i >= 0; i-- && t++) {
arr[maxIndex - t] = add[i];
}
}
function spreadOperator(arr, add){
arr.push(...add);
}
function shift(arr, add){
add = add.slice(0);
while (true) {
const x = add.shift();
if (x) {
arr.push(x)
} else {
return;
}
}
}
function concat(arr, add){
return arr.concat(add);
}
function testData(amount){
return new Array(amount).fill(0).map(() => {
return {
a: Math.random(),
b: Math.random()
}
})
}
const ar = testData(200000);
const add = testData(200);
Ready to run.
Test | Ops/sec | |
---|---|---|
noConstVar |
| ready |
withConstVar |
| ready |
addFromBehind |
| ready |
spreadOperator |
| ready |
shift |
| ready |
concat |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.