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
const prefix = "some-prefix";
const records = Array.from(
{length: 1000},
(_, i) => ({
idx: i,
name: `${prefix}.${i}.${btoa(Math.random())}`
})
);
function localVar() {
const n = prefix.length;
return records.map( (record) => ({
...record,
name: record.name.substring(n)
})
);
}
function dereference() {
return records.map( (record) => ({
...record,
name: record.name.substring(prefix.length)
})
);
}
function fixed() {
return records.map( (record) => ({
...record,
name: record.name.substring(11)
})
);
}
function compareSolns(arr1, arr2) {
if (arr1.length != arr2.length) {
console.error('bad arr length');
throw new Error('bad arr length');
}
arr1.forEach((e1, idx) => {
const e2 = arr2[idx];
if (e1.name != e2.name) {
console.error('bad elements', e1, e2);
throw new Error('bad elements');
}
});
}
const r1 = localVar();
const r2 = dereference();
const r3 = fixed();
compareSolns(r1, r2);
compareSolns(r1, r3);
Ready to run.
Test | Ops/sec | |
---|---|---|
local var |
| ready |
dereference |
| ready |
fixed |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.