Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array find vs _.find vs _.find (Array) vs _.find (Object)
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
array find vs _.find vs _.find (Object) vs _.find (Array)
Created:
5 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:
array find
var a = [{name: 'hello', something: 1}, {name: 'a', something: 1}, {name: 'bc', something: 1}]; var b = a.find(item => item.name === 'bc');
_.find
var a = [{name: 'hello', something: 1}, {name: 'a', something: 1}, {name: 'bc', something: 1}]; var b = _.find(a, item => item.name === 'bc');
_.find (Object)
var a = [{name: 'hello', something: 1}, {name: 'a', something: 1}, {name: 'bc', something: 1}]; var b = _.find(a, {name: 'bc'});
_.find (Array)
var a = [{name: 'hello', something: 1}, {name: 'a', something: 1}, {name: 'bc', something: 1}]; var b = _.find(a, ['name', 'bc']);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
array find
_.find
_.find (Object)
_.find (Array)
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 dive into the world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Definition** The benchmark is designed to compare four different approaches for finding an element in an array: 1. **`_.find()`**: A function from the Lodash library that finds the first element in an array that satisfies a predicate. 2. **`.find()`**: A built-in JavaScript method that does the same thing as `_.find()`. 3. **`.find()` with object literal**: Similar to `.find()`, but uses an object literal instead of a function. 4. **`.find()` with array literal**: Similar to `.find() with object literal`, but uses an array literal instead. **Options Compared** The benchmark compares the performance of these four approaches on an array of objects, where each object has a `name` property that we want to search for. The options are compared in terms of their execution time per iteration. **Pros and Cons of Each Approach** 1. **`.find()`**: This approach is simple and easy to read, but it can be slower than the others because it requires creating an iterator object. 2. **`_.find()`**: This approach is optimized for performance and uses a more efficient algorithm than `.find()`. 3. **`.find()` with object literal**: This approach is similar to `.find()`, but uses an object literal instead of a function. It can be slower because the JavaScript engine needs to parse the object literal. 4. **`.find()` with array literal**: This approach is similar to `.find()` with object literal, but uses an array literal instead. It can also be slower due to parsing. **Libraries Used** The benchmark uses Lodash (version 4.17.5) as a dependency. Specifically, it uses the `lodash.core` module for the `_` alias. **Special JS Features/Syntax** There are no special JavaScript features or syntax used in this benchmark. **Other Considerations** * The benchmark is run on Chrome 88 with a Mac OS X 11.2.0 platform. * The results show that `.find()` and `_.find()` are generally faster than the other two approaches. * The `find()` with object literal and array literal approaches can be slower due to parsing. **Alternatives** If you're interested in exploring alternative approaches, here are some options: * Use `Array.prototype.findIndex()` instead of `_.find()`. This method is similar but returns `-1` if no element is found. * Use a custom loop with indexing instead of the built-in `.find()` or Lodash methods. This can be slower and more verbose. * Compare performance using other benchmarking tools, such as Benchmark.js or Jest. I hope this explanation helps you understand the MeasureThat.net benchmark!
Related benchmarks:
native find vs lodash _.find..
array find vs some vs lodash
native find vs lodash _.find_fork
Compare prototype.find vs lodash/find
Comments
Confirm delete:
Do you really want to delete benchmark?