Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.values(...).find(...) vs _.find(...,...)
(version: 0)
Comparing performance of:
Object.values(...).find(...) vs _.find(...,...)
Created:
3 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>
Tests:
Object.values(...).find(...)
const object = { a: { id: 1 }, b: { id: 2 }, c: { id: 3 }, d: { id: 4 }, e: { id: 5 } } const found = Object.values(object).find(x => x.id === 5)
_.find(...,...)
const object = { a: { id: 1 }, b: { id: 2 }, c: { id: 3 }, d: { id: 4 }, e: { id: 5 } } const found = _.find(object, { id: 5 });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object.values(...).find(...)
_.find(...,...)
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 benchmark definition and test cases. **What is tested?** The provided JSON represents two microbenchmarks that compare the performance of two approaches: 1. Using `Object.values()` to get an array of object values, followed by `Array.prototype.find()`, which finds the first element in the array that satisfies a predicate. 2. Using Lodash's `_find()` function with an options object containing the value to find (`id: 5`) and its corresponding key (`key: 'id'`). **Options compared** The two approaches are compared on how they access and search for the desired value within the nested object. * Approach 1 (Object.values(...).find()): This approach uses the `Object.values()` method to get an array of the object's values, which is then passed to the `Array.prototype.find()` method. * Approach 2 (_.find(...,...)): This approach uses Lodash's `_find()` function, which takes two arguments: the value to find (`id: 5`) and its corresponding key (`key: 'id'`). **Pros and cons of each approach** **Approach 1 (Object.values(...).find())** Pros: * Simple and straightforward * No additional dependencies required Cons: * May have performance overhead due to the creation of an array of object values * Requires two method calls, which can be expensive **Approach 2 (_.find(...,...))** Pros: * More efficient since it uses a native JavaScript function * Can handle more complex search scenarios with additional options Cons: * Requires Lodash as a dependency * May have performance overhead due to the creation of an options object **Library used: Lodash** Lodash is a popular JavaScript utility library that provides various functions for tasks like array manipulation, object manipulation, and more. In this benchmark, `_find()` is used to find a value in an array based on a predicate. **Special JS feature or syntax not mentioned** None. **Other alternatives** If you want to compare these approaches without using Lodash, you could use other native JavaScript functions like `Array.prototype.findIndex()`, which has similar functionality but with some differences: * `Array.prototype.findIndex()` returns the index of the first element that satisfies the predicate, whereas `_find()` returns the found value. * `Array.prototype.findIndex()` takes only one argument: a predicate function. Keep in mind that the performance difference between these approaches may be negligible for small datasets. However, as the dataset grows, using an efficient library like Lodash or a native JavaScript function like `Array.prototype.findIndex()` can make a significant difference.
Related benchmarks:
Array find vs lodash _.find
native find vs lodash _.find equal
String vs Object find
Lodash vs Native Find
native find vs lodash _.find for objects equality
Comments
Confirm delete:
Do you really want to delete benchmark?