Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Data normalization
(version: 0)
Comparing performance of:
reduce with same obj vs fromEntries
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var data = Object.entries({ ...Array.from(Array(10000).keys()) });
Tests:
reduce with same obj
data.reduce((map, [price, vol]) => { map[price] = vol; return map; }, {});
fromEntries
Object.fromEntries(data);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
reduce with same obj
fromEntries
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON data and explain what's being tested, compared, and discussed. **Benchmark Definition** The benchmark is focused on measuring the performance difference between two approaches: reducing an array of objects into a single object using `Array.prototype.reduce()` and creating the same object using `Object.fromEntries()`. The input data consists of 10,000 key-value pairs stored in an array of arrays, where each inner array contains a price and a volume. **Script Preparation Code** The script preparation code defines the input data: ```javascript var data = Object.entries({ ...Array.from(Array(10000).keys()) }); ``` This creates an object with 10,000 key-value pairs, where each key is a unique integer from 0 to 9,999 and the corresponding value is `undefined`. **Html Preparation Code** There is no HTML preparation code provided. **Options Being Compared** The two options being compared are: 1. **`Array.prototype.reduce()`**: This method applies a reduction function to each element in the array and accumulates a result. In this case, it's used to create an object with price as keys and volume as values. 2. **`Object.fromEntries()`**: This method creates a new object from an iterable of key-value pairs. **Pros and Cons** * `Array.prototype.reduce()`: Pros: + Can handle non-integer keys (arrays can be used as keys). + May be more efficient for large datasets due to its ability to accumulate the result. * Cons: + Requires iterating over the entire array, which may lead to slower performance for very large datasets. + Can be less readable than `Object.fromEntries()` for complex operations. * `Object.fromEntries()`: Pros: + Creates a new object with keys and values from an iterable of key-value pairs. + More readable and concise than `Array.prototype.reduce()`. * Cons: + Limited to only using iterables as input (arrays, maps, sets). + May be less efficient for very large datasets due to the creation of multiple intermediate arrays. **Library** In this benchmark, there are no external libraries being used. **Special JavaScript Features or Syntax** There are no special features or syntax mentioned in the provided code. The standard JavaScript `reduce()` and `Object.fromEntries()` methods are used without any additional options or customizations. **Other Alternatives** For comparison purposes, other alternatives to these two options could include: * Using `Array.prototype.forEach()` and a callback function to iterate over the array and create an object. * Using `Array.prototype.map()` to create an array of key-value pairs and then using `Object.fromEntries()` or `reduce()` to create the final object. However, it's worth noting that these alternatives would likely introduce more overhead due to additional memory allocations and operations.
Related benchmarks:
Map vs Object with Number Keys
Map convert
for in / object.keys test
Object.fromEntries vs for at scale
Object reduction with conversion back
Comments
Confirm delete:
Do you really want to delete benchmark?