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
Comparison of splice- and slice-based array reordering routines
const length = 10000
const list = new Array(length)
for (let i = 0; i < length; i++) {
list[i] = i + 1
}
const spliceBasedArrayReordering = (list, startIndex, endIndex) => {
const result = Array.from(list)
const [removed] = result.splice(startIndex, 1)
result.splice(endIndex, 0, removed)
return result
}
const sliceBasedArrayReordering = (list, startIndex, endIndex) => {
const intermediate = [...list.slice(0, startIndex), ...list.slice(startIndex + 1)]
const result = [...intermediate.slice(0, endIndex), list[startIndex], ...intermediate.slice(endIndex + 1)]
return result
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Splice-based array reordering |
| ready |
Slice-based array reordering |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.