Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test keyby vs looped findby
(version: 1)
Comparing performance of:
looped findby vs keyByTest
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
const users = [{id: 1, name: 'cool'}, {id:2, name: 'cool2'}, {id:3, name: 'cool3'}]; const usersWithPerms = [{id: 1, perm: 'yes'}, {id:2, perm: 'no'}, {id:3, perm: 'yes'}]; var loopedFindBy = () => { const result = []; users.forEach((user) => { const rawEntry = usersWithPerms.find( (entry) => entry.id === user.id ); result.push(rawEntry); }); return result; } var keyByTest = () => { const result = []; const userPermsById = _.keyBy(usersWithPerms, 'id'); users.forEach((user) => { const rawEntry = userPermsById[user.id]; result.push(rawEntry); }) return result; }
Tests:
looped findby
loopedFindBy();
keyByTest
keyByTest();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
looped findby
keyByTest
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0
Browser/OS:
Chrome 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
looped findby
8530335.0 Ops/sec
keyByTest
2293635.5 Ops/sec
Related benchmarks:
Object.keys vs for...in
Object.keys vs for...in with more items
Find vs Map (recalculated each time)
Some vs Find vs Loop
Some vs Find vs. keys and values
For_Oksana
map/join vs reduce objects
const in a for loop
object record find 2
Comments
Confirm delete:
Do you really want to delete benchmark?