Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.fromEntries vs for...of vs for (C style)
(version: 2)
Comparing performance of:
Object.fromEntries vs for...of vs for (C style) vs forEach
Created:
one month ago
by:
Registered User
Jump to the latest result
Script Preparation code:
const data = Array(10000); for (let i=0; i<data.length; i++) { data[i] = i; }
Tests:
Object.fromEntries
const a = Object.fromEntries(data.map((idx) => ["id-"+idx, idx]));
for...of
const a = {} for (const idx of data) { a["id-"+idx] = idx; }
for (C style)
const a = {} for (let i=0; i<data.length; i++) { const idx = data[i]; a["id-"+idx] = idx; }
forEach
const a = {} data.forEach(idx => a["id-"+idx] = idx);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Object.fromEntries
for...of
for (C style)
forEach
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0
Browser/OS:
Firefox 150 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object.fromEntries
754.7 Ops/sec
for...of
886.5 Ops/sec
for (C style)
865.1 Ops/sec
forEach
886.8 Ops/sec
Related benchmarks:
Array.reduce
using data set. array vs object
set in loop vs at the end
for in vs object.keys
for-in vs object.keys + for
object.keys vs length variable
for-in vs for-of
object record find 2
Object.fromEntries vs classic for (fixed: Object.fromEntries)
Comments
Confirm delete:
Do you really want to delete benchmark?