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 OUT_OF_BOUNDS = Symbol("OOB");
function steamrollArray(input) {
const loc = [0];
const steamrolled = [];
while(loc[0] < input.length) {
const val = loc.reduce(
(v, i) => Array.isArray(v) && i < v.length ?
v[i] :
OUT_OF_BOUNDS,
input,
);
if (Array.isArray(val)) {
loc.push(-1);
} else if (val === OUT_OF_BOUNDS) {
loc.pop();
} else {
steamrolled.push(val);
}
loc[loc.length - 1]++;
}
return steamrolled;
}
const steamrollArray2 = (array) => {
let isFinished = array.every(el => !Array.isArray(el));
while (!isFinished) {
for (const index in array) {
if (Array.isArray(array[index])) {
array.splice(index, 1, ...array[index])
}
}
isFinished = array.every(el => !Array.isArray(el))
}
return array;
}
Ready to run.
| Test | Ops/sec | |
|---|---|---|
| My solution | | ready |
| Naomi's Cheater Solution | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.