Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.fromEntries vs create temp object
(version: 0)
Comparing performance of:
Object.fromEntries vs creating temporary objects
Created:
5 years ago
by:
Guest
Go to the latest result
Script Preparation code:
var array = Array.from(Array(10000).keys())
Tests:
Object.fromEntries
Object.fromEntries(array.map(value => [value, value]));
creating temporary objects
const data = {} array.forEach(value => data[value] = value);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object.fromEntries
creating temporary objects
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
creating temporary objects
14K/s
Object.fromEntries
2K/s
View exact numbers
Test name
Executions per second
✓
creating temporary objects
14,254 Ops/sec
Object.fromEntries
1,714 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark is comparing two approaches to create objects in JavaScript: 1. Using `Object.fromEntries` with an array of key-value pairs. 2. Creating a temporary object using an array's `forEach` method. **Options Being Compared** * `Object.fromEntries`: A built-in JavaScript method introduced in ECMAScript 2015 (ES6), which creates a new object from an iterable of key-value pairs. * Creating a temporary object: This approach involves iterating over the array and assigning each value to a property on a newly created object. **Pros and Cons** * `Object.fromEntries`: + Pros: - Concise and expressive syntax - Creates a new object without modifying an existing one + Cons: - May be slower due to the overhead of creating a new object and iterating over the array * Creating a temporary object: + Pros: - May be faster since it avoids the overhead of creating a new object + Cons: - More verbose syntax compared to `Object.fromEntries` - Requires more memory allocation and garbage collection **Library Usage** There is no explicit library usage in this benchmark. However, the `Array.from()` method is used to create an array from another iterable (in this case, an array of numbers). **Special JS Features/Syntax** * There are no special JavaScript features or syntax specific to this benchmark. **Other Considerations** The benchmark results are based on the Chrome 90 browser running on a desktop Windows platform. The test is designed to measure the execution speed of each approach, with multiple executions per second reported. **Alternative Approaches** Other approaches to create objects in JavaScript could include: * Using `Array.prototype.reduce()` or other aggregation methods * Creating an object using a loop and assigning properties manually * Using a library like Lodash or Underscore.js for object creation However, these alternatives are not being tested in this specific benchmark.
Related benchmarks
Object.fromEntries vs create temp object vs Array.reduce
Array.forEach vs Object.keys().forEach
Object.fromEntries vs Map
Comments
Confirm delete:
Do you really want to delete benchmark?