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 xbonacci_fast(signature, maxLength) {
if (maxLength < signature.length) return signature.slice(0, maxLength);
const length = signature.length;
let initialSum = signature.reduce((acc, cur) => acc + cur, 0);
const res = [...signature, initialSum];
initialSum -= res[0]; // remove first element to prepare for the loop
for (let i = length; i < maxLength - 1; i++) {
initialSum += res[res.length - 1];
res.push(initialSum);
initialSum -= res[res.length - length - 1];
}
return res;
}
function xbonacci_slow(signature, n){
const x = signature.length;
const arr = [...signature];
for(let i = 0; i < n-x; i++) {
arr.push(arr.slice(i, i+x).reduce((p,c)=>p+c));
}
return arr.slice(0,n);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Performant version |
| ready |
"Tidy" version |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.