Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Object key sorting: forEach vs Object.fromEntries 2
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser:
Chrome 142
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
6 months ago
Test name
Executions per second
forEach
9139.6 Ops/sec
Object.fromEntries
1141.0 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const testObj1 = {}; const testObj2 = {}; for (let i = 0; i < 1000; i++) { testObj1[`key_${Math.random().toString(36).substring(7)}`] = Math.random(); testObj2[`key_${Math.random().toString(36).substring(7)}`] = Math.random(); } function keySortedForEach(obj) { const sortedKeys = Object.keys(obj).sort(); const sortedObj = {}; sortedKeys.forEach(key => { sortedObj[key] = obj[key]; }); return sortedObj; } function keySortedFromEntries(obj) { return Object.fromEntries( Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)) ); }
Tests:
forEach
// Benchmark 1 keySortedForEach(testObj1);
Object.fromEntries
// Benchmark 2 keySortedFromEntries(testObj2);