Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.fromEntries vs Map
(version: 0)
Comparing performance of:
Object.fromEntries vs Map
Created:
one year ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var data = Object.entries({ ...Array.from(Array(10000).keys()) }).map((key, value) => [key, value]);
Tests:
Object.fromEntries
Object.fromEntries(data);
Map
new Map(data)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object.fromEntries
Map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:145.0) Gecko/20100101 Firefox/145.0
Browser/OS:
Firefox 145 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object.fromEntries
426.3 Ops/sec
Map
1832.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided JSON represents a JavaScript microbenchmark that compares the performance of two data structures: `Object.fromEntries` and `Map`. The benchmark is designed to measure which approach is faster for creating an object from an array of key-value pairs. **Script Preparation Code** The script preparation code creates a dataset by: 1. Generating an array of 10,000 keys using `Array.from(Array(10000).keys())`. 2. Creating an array of equivalent key-value pairs using `Object.entries`. The resulting data is then passed to both the `Object.fromEntries` and `Map` methods. **Options Compared** Two options are compared in this benchmark: 1. **Object.fromEntries**: This method creates a new object by taking an iterable of key-value pairs as an argument. 2. **Map**: A built-in JavaScript data structure that stores key-value pairs in an ordered collection. **Pros and Cons of Each Approach** * **Object.fromEntries**: + Pros: - More intuitive for creating objects with named properties (e.g., `const obj = Object.fromEntries([...])`). - Can be more readable for simple cases. + Cons: - May have slower performance due to the overhead of object creation and property access. * **Map**: + Pros: - Often faster than `Object.fromEntries` because it avoids the overhead of object creation and property access. - More efficient for large datasets or when working with multiple key-value pairs. + Cons: - Less intuitive for creating objects with named properties (e.g., `const obj = new Map([...])`). **Library/Function Used** None, as both methods are built into JavaScript. **Special JS Feature/Syntax** No special features or syntax are used in this benchmark. However, if you're interested in exploring other performance comparisons, MeasureThat.net also tests various other JavaScript methods and libraries. **Other Alternatives** If you're looking for alternatives to `Object.fromEntries` and `Map`, consider the following: * For creating objects: + `JSON.parse(JSON.stringify(data))`: A simple way to create an object from a JSON-like data structure. + `Array.prototype.reduce()`: Can be used to create an object by reducing an array of key-value pairs. * For working with key-value pairs: + `Array.prototype.forEach()`: Can be used to iterate over key-value pairs in an array. + `Set` or `Map` alternatives, such as `Array.prototype.reduce()` or third-party libraries like Lodash. Keep in mind that the choice of method depends on your specific use case and requirements.
Related benchmarks:
reduce (immutable) vs map + fromEntries
Object.fromEntries vs create temp object
Object.fromEntries vs create temp object vs Array.reduce
Map convert
Comments
Confirm delete:
Do you really want to delete benchmark?