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 createArray = () => new Array(1000000).fill(0).map(i => Math.random());
const remove1 = (arr, startIdx, removeCount) => {arr.splice(startIdx, removeCount)};
const remove2 = (arr, startIdx, removeCount) => {
const length = arr.length;
if (startIdx >= length || removeCount === 0) {
return;
}
removeCount = (startIdx + removeCount > length ? length - startIdx : removeCount);
const len = length - removeCount;
for (let i = startIdx; i < len; ++i) {
arr[i] = arr[i + removeCount];
}
arr.length = len;
};
const runTest = (removeFn) => {
const arr = createArray();
for (let i = 0; i < 1000; ++i) {
const idx = Math.floor(Math.random() * arr.length);
const count = Math.floor(Math.random() * 100);
removeFn(arr, idx, count);
}
};
Ready to run.
Test | Ops/sec | |
---|---|---|
splice |
| ready |
removeItems |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.