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 groupBy(
items,
createKey,
createValue
) {
return items.reduce((result, item) => {
const key = createKey(item)
// If there is no createValue function, Item and Value are the same.
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const value = createValue?.item || item
if (result.has(key)) {
result.get(key)?.push(value)
} else {
result.set(key, [value])
}
return result
}, new Map())
}
const data = Array.from({length: 1000}, (_, idx) => ({id: idx % 250, otherValue: Math.random(), otherValue2: Math.random()}))Ready to run.
| Test | Ops/sec | |
|---|---|---|
| custom groupBy Function | | ready |
| native Map.groupBy | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.