Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array-group-test
(version: 0)
Comparing performance of:
A (2 cycles) vs B (1 cycle + map)
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var groups = [['E', 'E_T'], ['T', 'T_T']]; var elements = [ { t: 'E', cls: 'E' }, { t: 'EU', cls: 'E_T' }, { t: 'EC', cls: 'E_T' }, { t: 'B', cls: 'B' }, { t: 'T', cls: 'T' }, { t: 'TU', cls: 'T_T' }, ];
Tests:
A (2 cycles)
const temp = {}; for (const cGroup of groups) { const key = cGroup.join(); for (const el of elements) { if (!cGroup.includes(el.cls)) { continue; } if (!temp[key]) { temp[key] = [el]; } else { temp[key].push(el); } } } const res = []; for (const cGroup of Object.values(temp)) { res.push(cGroup); }
B (1 cycle + map)
const keyToIdx = {}; const res = []; for (const cGroup of groups) { const key = cGroup.join(); for (const el of elements) { if (!cGroup.includes(el.cls)) { continue; } const groupIdx = keyToIdx[key]; if (groupIdx > -1) { res[groupIdx].push(el); } else { keyToIdx[key] = (res.push([el]) - 1); } } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
A (2 cycles)
B (1 cycle + map)
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:
Spread vs object assign
Array find test
EGO concat vs spread Small Array Objects
my map vs for loop
_.forEach() vs _.each() vs [].forEach()
Comments
Confirm delete:
Do you really want to delete benchmark?