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
(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:
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/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object.values()
72024.7 Ops/sec
Array.map()
2768.6 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 designed to compare the performance of two approaches: 1. `Object.values(objects)` 2. `list.map((idx) => { objects[idx] })` These approaches aim to create an array list from a large dataset (10000 elements). The test measures which approach performs better in terms of speed. **Approach 1: Object.values(objects)** This approach uses the `Object.values()` method, which returns an array of values of the properties of an object. In this case, `objects` is an object created from another array list using `Object.fromEntries()`. The idea is to extract all the property values (which are just the index and title) into a new array. **Approach 2: Array.map((idx) => { objects[idx] })** This approach uses the `Array.map()` method, which applies a function to each element of an array. In this case, the function takes an index as input and returns the corresponding property value from the `objects` array using object indexing (e.g., `objects[idx]`). The result is a new array with the same number of elements. **Pros and Cons** **Object.values(objects)** Pros: * Concise code * No explicit looping required Cons: * May not be as efficient due to object lookup overhead * Requires an existing object (which might not always be available) **Array.map((idx) => { objects[idx] })** Pros: * More control over the iteration process * Easier to modify or add functionality for each element Cons: * More verbose code * Requires explicit looping and indexing **Library Usage** The `Object.fromEntries()` method is a modern JavaScript feature introduced in ECMAScript 2015 (ES6). It allows creating an object from an iterable array of key-value pairs. This library usage is not specific to any particular framework or library, but rather a standard JavaScript method. **Special JS Feature/Syntax** There are no special JavaScript features or syntaxes being tested in this benchmark. The code only uses standard JavaScript methods and data structures (arrays, objects). **Other Alternatives** If you're looking for alternative approaches to create an array list from another dataset: 1. **For...of loop**: `var list = Array.from({ length: 10000 }, (_, idx) => idx);` 2. **Array.prototype.forEach()**: `var list = [ ... ]; var objects = []; list.forEach((idx, i) => { objects.push({ index: idx, title: 'test' }); })` 3. **Destructuring assignment**: This approach is similar to using `Object.fromEntries()` but with a more concise syntax. These alternatives may have different trade-offs in terms of performance, readability, and maintainability, depending on your specific use case.
Related benchmarks:
10k: Test Object.values vs array map for creating object array list v2
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?