Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object key sorting: forEach vs Object.fromEntries
(version: 1)
Comparing performance of:
forEach vs Object.fromEntries
Created:
6 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const testObj = {}; for (let i = 0; i < 1000; i++) { testObj[`key_${Math.random().toString(36).substring(7)}`] = Math.random(); }
Tests:
forEach
function keySortedForEach(obj) { const sortedKeys = Object.keys(obj).sort(); const sortedObj = {}; sortedKeys.forEach(key => { sortedObj[key] = obj[key]; }); return sortedObj; } // Benchmark 1 keySortedForEach(testObj);
Object.fromEntries
function keySortedFromEntries(obj) { return Object.fromEntries( Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)) ); } // Benchmark 2 keySortedFromEntries(testObj);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
forEach
Object.fromEntries
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!
Comments
Confirm delete:
Do you really want to delete benchmark?