Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.values VS Object.keys.map
(version: 0)
Comparing performance of:
Object.values vs Object.keys.map
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function makeid() { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (var i = 0; i < 5; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } window.parentObj = {}; for (let i = 0; i < 100; i++) { window.parentObj[makeid()] = makeid(); }
Tests:
Object.values
const testArray = []; Object.values(window.parentObj).forEach(v => { testArray.push(v); });
Object.keys.map
const testArray = []; Object.keys(window.parentObj).map(k => { testArray.push(window.parentObj[k]); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object.values
Object.keys.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 comparing two approaches: 1. `Object.values(window.parentObj)` 2. `Object.keys(window.parentObj).map(k => window.parentObj[k])` These two approaches are testing how fast they can iterate over the values or keys of an object, respectively. **Options Compared** The options being compared are: * Iterating directly over the object's values using `Object.values` * Creating a new array by mapping over the object's keys and then accessing the corresponding value in the original object **Pros and Cons** 1. **Direct Iteration (`Object.values`)**: * Pros: Faster, more efficient, as it avoids the overhead of creating an intermediate array. * Cons: Limited to iterating over values only. 2. **Key-Value Mapping (`Object.keys.map`)**: * Pros: Can iterate over both keys and values, providing a more comprehensive view of the object. * Cons: Requires additional memory allocation for the intermediate array created by `map`, which can lead to slower performance. **Library Usage** The benchmark uses the `window.parentObj` object, which is a global object provided by MeasureThat.net. It appears to be an empty object that is populated with random IDs in the script preparation code. The `Object.values` and `Object.keys.map` functions are built-in JavaScript methods, so no additional libraries are required. **Special JS Feature/Syntax** There doesn't appear to be any special JavaScript features or syntax used in this benchmark. It's a straightforward comparison of two object iteration approaches. **Other Alternatives** If you wanted to compare other approaches, some alternatives could include: * Using `for...in` or `for...of` loops to iterate over the object's properties. * Using libraries like Lodash or Underscore.js that provide optimized iteration functions. * Using native WebAssembly (WASM) for faster execution. Keep in mind that these alternatives would require significant changes to the benchmark code and may not be as relevant to this specific comparison.
Related benchmarks:
Map vs Array vs Object set uint32 key speed
Map vs Array vs Object has uint32 key speed
Object.keys vs Object.values
Object keys vs Array map v2
keys vs values
Comments
Confirm delete:
Do you really want to delete benchmark?