Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object values vs _.values vs my-values
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
Object values vs _.values vs my-values
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.core.js"></script>
Script Preparation code:
function getValues(obj) { const t = []; for(var key in obj) { t.push(obj[key]); } return t; }
Tests:
Object values
var a = { a: 1, b: 2, c: 3}; Object.values(a);
_.values
var a = { a: 1, b: 2, c: 3}; _.values(a);
my-values
var a = { a: 1, b: 2, c: 3}; getValues(a);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Object values
_.values
my-values
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):
**Overview** The provided JSON represents a benchmark test on MeasureThat.net, which compares the performance of three approaches to extract values from an object: `Object.values()`, `_` (Lodash) function `values()`, and a custom implementation `getValues()`. The test aims to evaluate the efficiency of these methods in different JavaScript environments. **What is tested** The benchmark tests the following: 1. **Object.values()**: This method was introduced in ECMAScript 2019 as a part of the standard language specification. It returns an array containing all own property values of a given object. 2. **_.values()**: This function is part of the Lodash library and returns an array of values from an object. 3. **getValues()**: A custom implementation that uses a `for...in` loop to push each value from the object into an array. **Options compared** The benchmark compares the performance of these three approaches: * `Object.values()` * `_`.values() * `getValues()` Each approach has its pros and cons: * **Object.values()**: Pros: + Fastest and most efficient way to extract values from an object. + Part of the ECMAScript standard, making it widely supported. Cons: + Only available in ECMAScript 2019 and later versions. * **_.values()**: Pros: + Widely used and supported due to its presence in Lodash library. + Easy to use and understand for developers familiar with Lodash. Cons: + May introduce additional overhead due to the library's complexity. * **getValues()**: Pros: + Custom implementation, which can be optimized for specific use cases. Cons: + May require more effort to implement correctly. + Less efficient than `Object.values()` and `_`.values(). **Other considerations** When choosing an approach, consider the following factors: * Performance: If speed is critical, `Object.values()` is likely the best choice. For less performance-critical scenarios, `_`.values()` or `getValues()` might be acceptable. * Maintainability: If code readability and maintainability are important, `_`.values()` with its concise syntax might be a better option. * Compatibility: If you need to support older browsers or environments that don't have ECMAScript 2019 support, consider using `_`.values() or `getValues()`. **Library usage** In the benchmark, Lodash is used as the underlying library for the `_.values()` function. Lodash provides a wide range of utility functions and helps developers write more efficient and concise code. **Special JS feature/syntax** The benchmark uses ECMAScript 2019 syntax (`Object.values()`) and does not require any special JavaScript features or syntax beyond what is available in modern browsers. I hope this explanation helps!
Related benchmarks:
Object values vs _.values
Object keys vs _.values
Performance of Object.values(obj) vs_.values() vs for...in to extract values from an object with 1000 entries-3
Object values vs lodash _.values
Comments
Confirm delete:
Do you really want to delete benchmark?