Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Creating dictionary with fromEntries vs reduce (fork)
(version: 0)
Comparing performance of:
fromEntries vs reduce
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var data = [ ...Array(100000) ].map(() => ({ id: Math.round(Math.random() * 1e8), value: `Information ${Math.round(Math.random() * 1e5)}` }))
Tests:
fromEntries
Object.fromEntries(data.map((obj => [obj.id, obj])))
reduce
data.reduce((acc, obj) => { acc[obj.id] = obj return acc }, {})
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
fromEntries
reduce
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
fromEntries
78.7 Ops/sec
reduce
104.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested, compared, and the pros and cons of each approach. **Benchmark Context** The test case measures the performance difference between two approaches to create an object from an array of key-value pairs: `Object.fromEntries()` and the `.reduce()` method. Both methods are used to convert an array of key-value pairs into a JavaScript object. **Options Compared** Two options are compared: 1. **`Object.fromEntries()`**: This method was introduced in ECMAScript 2017 (ES8) as part of the Object.prototype property accessor syntax. It takes an iterable (such as an array) and converts it into an object with the key-value pairs from the iterable. 2. **`.reduce()` method**: The `.reduce()` method is a fundamental method in JavaScript that applies a callback function to each element of an array, accumulating a value or an object. **Pros and Cons** Here's a brief overview of the pros and cons of each approach: ### `Object.fromEntries()` Pros: * Concise and readable syntax * Faster execution (in general) compared to `.reduce()` due to the language's optimization for object creation Cons: * Only supported in ECMAScript 2017 (ES8) and later versions. Older browsers might not support it. * Requires modern JavaScript engines to execute efficiently. ### `.reduce()` method Pros: * Widely supported across older browsers and environments * More flexible, as the callback function can perform any operation on each element * Can be used for other purposes beyond object creation Cons: * Less concise syntax compared to `Object.fromEntries()` * Might be slower due to the overhead of the language's internal mechanisms for array iteration and accumulation. **Library Usage** None in this benchmark. **Special JS Features or Syntax** No special features are mentioned, as the test case only uses standard JavaScript methods and does not rely on any advanced syntax or features.
Related benchmarks:
Map & Object.fromEntries vs reduce
Object.fromEntries on array vs reduce on array
flatMap vs reduce test
Object.fromEntries vs reduce round 2
push vs spread (reduce array)
Comments
Confirm delete:
Do you really want to delete benchmark?