Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash some vs JavaScript Object.values and some
(version: 1)
Comparing performance of: Lodash vs Native
Comparing performance of:
Lodash some vs JavaScript Object.values and some
Created:
one year 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:
var values = {a: true, b: false, c: false, d: false, e: false};
Tests:
Lodash some
_.some(values, val => val === true);
JavaScript Object.values and some
Object.values(values).some(val => val === true);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash some
JavaScript Object.values and some
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/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash some
15684829.0 Ops/sec
JavaScript Object.values and some
43802256.0 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The benchmark being tested is a performance comparison between two methods of checking if any value in a set of object properties is `true`. The approaches compared are: 1. **Lodash's `_.some` Method**: - **Benchmark Definition**: `_.some(values, val => val === true);` - **Library**: Lodash is a popular utility library in JavaScript that provides a wide range of functions to make working with arrays, objects, and other data types easier and more efficient. The `_.some` method checks if at least one element in a collection passes a given predicate (in this case, whether the value is `true`). 2. **Native JavaScript Approach**: - **Benchmark Definition**: `Object.values(values).some(val => val === true);` - **Explanation**: This approach uses the native JavaScript `Object.values()` method, which retrieves an array of a given object's own enumerable property values. It then applies the native `some` method on the resulting array to determine if any of the values meet the specified condition. ### Pros and Cons: **Lodash Approach**: - **Pros**: - Provides a uniform API for various data types and structures. - Might be more intuitive for developers familiar with functional programming paradigms. - Can be easier to read in some contexts, particularly when chaining multiple operations. - **Cons**: - Adds an external dependency to a project, which can increase bundle size and potentially lead to version conflicts. - May have performance overhead compared to native methods due to abstraction layers. **Native Approach**: - **Pros**: - No external dependencies are required, leading to smaller bundle sizes and reduced complexity. - Generally has better performance because it directly uses built-in JavaScript methods optimally implemented by the engine. - More straightforward for developers who are proficient with JavaScript and prefer to avoid additional libraries. - **Cons**: - May require more boilerplate code when dealing with complex operations as compared to Lodash's chaining capabilities. - Not as many helper functions available for more complex data manipulations. ### Considerations: 1. **Performance**: The benchmark results indicate that the native approach using `Object.values()` and `some` is significantly faster than the Lodash approach, with `JavaScript Object.values and some` executing about 4.38 times more operations per second compared to `Lodash some`. 2. **Readability and Maintainability**: The choice between using Lodash or native methods can also depend on team preferences, code style guidelines, and the specific use cases. For simple checks, native methods perform extremely well and maintain clarity. 3. **Use Case**: If the codebase already uses Lodash extensively, sticking to it for consistency might make sense. However, for new projects or simple tasks, using native JavaScript is often the better and more efficient choice. ### Alternatives: - For checking conditions in arrays or collections, developers might also consider methods like `forEach`, `filter`, and even a traditional `for` loop, but these may not be as concise or expressive as using `some`. - In cases where performance is paramount, exploring other libraries designed explicitly for performance or using WebAssembly for computationally intensive tasks could be alternatives, albeit at the cost of additional complexity.
Related benchmarks:
lodash.keys vs Object.keys
lodash.keys vs Object.keys
lodash.keys vs Object.keys
lodash.keys [4.17.11] vs Object.keys
lodash.values vs Object.values
Lodash values vs Object.values
Object.values vs _.values
Native Object.values().some() vs lodash _.some()
Object.values vs lodash values
Comments
Confirm delete:
Do you really want to delete benchmark?