Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.values vs _.values vs for in
(version: 0)
Comparing performance of:
Object.values vs _.values vs for in
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
function extractValues(obj) { const values = []; for(var key in obj) { values.push(obj[key]); } return values; }
Tests:
Object.values
Object.values({ a: 1, b: 2, c: 3 });
_.values
_.values({ a: 1, b: 2, c: 3 });
for in
extractValues({ a: 1, b: 2, c: 3 });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Object.values
_.values
for in
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object.values
23440548.0 Ops/sec
_.values
32739830.0 Ops/sec
for in
59694104.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** The provided JSON represents a JavaScript microbenchmark test case on the MeasureThat.net website. The benchmark compares three approaches to extract values from an object: 1. `Object.values()` 2. `_values()` (a function from the Lodash library) 3. A custom implementation using a `for...in` loop (`extractValues()`) **Options Compared** The benchmark tests the execution speed of each approach on the same input data: an object with three properties (`{ a: 1, b: 2, c: 3 }`). The options are compared in terms of their performance. **Pros and Cons of Each Approach** 1. **`Object.values()`**: * Pros: + Simple and concise syntax. + Built-in method, so no additional library needed. * Cons: + May not be as performant as custom implementations due to overhead from the built-in function call. 2. **_values()` (Lodash)**: * Pros: + Provides a consistent and predictable API for value extraction across different libraries and frameworks. + Reduces code duplication by providing a reusable utility function. * Cons: + Requires an additional library dependency, which may not be desirable in some cases. + May introduce performance overhead due to the extra function call. 3. **`extractValues()` (Custom)**: * Pros: + Highly optimized for performance, as it's a custom implementation with no overhead from built-in functions or libraries. * Cons: + More code and maintenance required compared to the other two options. **Library: Lodash** Lodash is a popular JavaScript utility library that provides various helper functions for tasks like array manipulation, object processing, and more. The `_values()` function in this benchmark is part of the Lodash library and is used to extract values from an object. **Special JS Feature/Syntax: None** There are no special JavaScript features or syntaxes being tested in this benchmark. The focus is solely on comparing the performance of different approaches for extracting values from an object. **Other Alternatives** If you need to extract values from an object, other alternatives could include: * Using `for...in` with a `forEach` loop (similar to the custom implementation) * Utilizing modern JavaScript features like destructuring assignment or `Object.entries()` * Implementing a custom array-like object for value extraction Keep in mind that these alternatives may have different trade-offs in terms of performance, readability, and maintainability.
Related benchmarks:
Performance of Object.values(obj) vs_.values() vs for...in to extract values from an object
Performance of Object.values(obj) vs_.values() vs for-in to extract values from an object
Performance of Object.values(obj) vs_.values() vs for...in to extract values from an object with 1000 entries-2
Performance of Object.values(obj) vs_.values() vs for...in to extract values from an object with 1000 entries-3
Comments
Confirm delete:
Do you really want to delete benchmark?