Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
10k: Test Object.values vs array map for creating object array list v2
(version: 0)
Comparing performance of:
Object.values() vs Array.map()
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var list = Array.from({ length: 10000 }).map((_, idx) => idx); var objects = Object.fromEntries(list.map((v, idx) => [idx, { index: idx, title: 'test' }]))
Tests:
Object.values()
Object.values(objects)
Array.map()
list.map((idx) => objects[idx])
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object.values()
Array.map()
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 and explain what's being tested. **Benchmark Definition** The benchmark is testing two approaches to create an array list of objects in JavaScript: 1. Using `Object.values()` to get the values from an object and then creating a new object array using those values. 2. Creating an array from a number of 10,000 elements and then mapping each element to create an object with a specific structure. **Options Compared** The two options being compared are: * **Approach 1: `Object.values()` + Object.fromEntries()** + This approach uses the `Object.values()` method to get the values from the `objects` object, which is created by mapping over an array of numbers. These values are then passed to the `Object.fromEntries()` method to create a new object array. * **Approach 2: Array.map() + Object.fromEntries()** + This approach uses the `Array.map()` method to create a new array with objects, where each object is created by mapping over an array of numbers. The resulting array is then passed to the `Object.fromEntries()` method to create a new object array. **Pros and Cons** * **Approach 1:** + Pros: - May be faster because it doesn't require creating an intermediate array. - Can take advantage of browser optimizations for getting values from objects. + Cons: - Requires an existing object with a specific structure, which may not be common. - May have higher overhead due to the use of `Object.values()` and `Object.fromEntries()`. * **Approach 2:** + Pros: - More straightforward and easy to understand. - Does not require an existing object with a specific structure. + Cons: - Requires creating an intermediate array, which may increase overhead. - May be slower due to the need for mapping over the array. **Library/Function** The `Object.values()` method is a built-in JavaScript method that returns an array of values from an object. The `Object.fromEntries()` method is also a built-in JavaScript method that creates a new object from an iterable of key-value pairs. **Special JS Feature/Syntax** There are no special JavaScript features or syntax used in this benchmark. **Other Alternatives** Other alternatives for creating an object array could include: * Using the spread operator (`{...}`) to create an object from an array of key-value pairs. * Using a library like Lodash's `fromPairs()` function. * Using a custom implementation that iterates over the array and creates objects manually. Keep in mind that these alternatives may have different performance characteristics and trade-offs compared to the two approaches being tested.
Related benchmarks:
10k: Test Object.values vs array map for creating object array list
Object.fromEntries vs create temp object
Array.from() vs new Array() with index
Object.fromEntries vs Map
Comments
Confirm delete:
Do you really want to delete benchmark?