Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Group by single pass vs multiple
(version: 0)
Comparing performance of:
n vs b
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var data = [ { name: 'john', savings: 900, firm: 'chase', advisor: 'holly' }, { name: 'carol', savings: 500, checking: 600, firm: 'chase', advisor: 'mark', }, { name: 'sarah', savings: 500, checking: 300, firm: 'chase', advisor: 'holly', }, { name: 'toby', savings: 500, checking: 300, firm: 'chase', advisor: 'mark' }, { name: 'casey', savings: 500, checking: 200, firm: 'citiBank', advisor: 'cindy', }, { name: 'bruce', checking: 200, firm: 'chase', advisor: 'holly' }, { name: 'jim', checking: 200, firm: 'chase', advisor: 'holly' }, { name: 'nich', firm: 'chase', advisor: 'mark' }, ];
Tests:
n
var keys = [ ['firm', 'advisors'], ['advisor', 'clients'], ]; var result = data.reduce( (r, o) => { keys .reduce((q, [key, children]) => { let name; ({ [key]: name, ...o } = o); if (!q[name]) { q[name] = { _: [] }; q._.push({ name, [children]: q[name]._ }); } return q[name]; }, r) ._.push(o); return r; }, { _: [] } )._;
b
function group(arr, accumulate) { let accumulator = {}; for (const obj of arr) { accumulator = accumulate(accumulator, obj); } return Object.values(accumulator); } function by(parentProp, childProp) { return function (acc, obj) { const { [parentProp]: name, ...child } = obj; (acc[name] ??= { name, [childProp]: [] })[childProp].push(child); return acc; }; } var result = group(data, by('firm', 'advisors')).map( ({ advisors, ...firm }) => ({ ...firm, advisors: group(advisors, by('advisor', 'clients')), }) );
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
n
b
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
lodash groupBy vs Array.reduce (1mln)
lodash groupBy vs lodash keyBy 2
Reduce with spread VS for...of with push
lodash groupBy vs filter 100k v1
lodash groupBy vs Array.reduce 100k better 2
Comments
Confirm delete:
Do you really want to delete benchmark?