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 keys = ["hello", "world", "wow", "this", "is", "fun"];
const values = [];
for (let i = 0; i < 100_000; i++) {
values.push([keys[Math.floor(Math.random() * keys.length)], i]);
}
function groupByForOf(iter, fn) {
const result = {};
for (const value of iter) {
const entry = (result[fn(value)] ||= []);
entry.push(value);
}
return result;
}
function groupByFor(iter, fn) {
const result = {};
for (let i = 0; i < iter.length; i++) {
const value = iter[i];
const entry = (result[fn(value)] ||= []);
entry.push(value);
}
return result
}
function groupByReduce(iter, fn) {
return iter.reduce((result, value) => {
const entry = (result[fn(value)] ||= []);
entry.push(value);
return result
}, {});
}
function groupByReduceSpread(iter, fn) {
return [...iter].reduce((groups, curr) => {
const key = fn(curr);
const group = groups[key] ?? [];
group.push(curr);
return { ...groups, [key]: group };
}, {});
}
Ready to run.
Test | Ops/sec | |
---|---|---|
reduce |
| ready |
for of loop |
| ready |
Object.groupBy |
| ready |
for loop |
| ready |
reduce, spreading arguments |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.