Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array find vs some vs lodash
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
array find vs array some vs lodash some
Created:
4 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 type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.core.js"></script>
Tests:
array find
var a = [{a: 'hello'}, {a: 'a'}, {a: 'bc'}, {a: 'ad'}, {a: 'mg'}, {a: 'asd'}]; var b = a.find(item => item.a === 'bc');
array some
var a = [{a: 'hello'}, {a: 'a'}, {a: 'bc'}, {a: 'ad'}, {a: 'mg'}, {a: 'asd'}]; var b = a.some(item => item.a === 'bc');
lodash some
var a = [{a: 'hello'}, {a: 'a'}, {a: 'bc'}, {a: 'ad'}, {a: 'mg'}, {a: 'asd'}]; var b = _.some(a, ['a', 'bc']);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
array find
array some
lodash some
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/132.0.0.0 Safari/537.36
Browser/OS:
Chrome 132 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array find
68782600.0 Ops/sec
array some
71516568.0 Ops/sec
lodash some
7736984.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the benchmark and explain what's being tested. **What is being tested?** The provided JSON represents a microbenchmark that compares three different approaches to filter an array: 1. `Array.prototype.find()`: This method returns the first element in the array that satisfies the provided condition. 2. `Array.prototype.some()`: This method returns `true` if at least one element in the array satisfies the provided condition. 3. `_` (lodash): A popular JavaScript library for functional programming utilities, including filtering functions. **Options compared** The benchmark compares three options: * `Array.prototype.find()` with a callback function * `Array.prototype.some()` with a callback function * `lodash.some()` with an array of values to filter **Pros and Cons** Here are some pros and cons for each approach: 1. `Array.prototype.find()`: * Pros: Efficient, straightforward, and easy to use. * Cons: Returns only the first matching element, may not be suitable for all use cases (e.g., when you need all matches). 2. `Array.prototype.some()`: * Pros: More efficient than using `find()` in a loop, returns as soon as it finds the first match, and is more concise. * Cons: May return false if no match is found, whereas `find()` returns undefined. 3. `lodash.some()`: * Pros: Offers more flexibility and control over filtering, can be used with arrays of values, and is often faster than native methods. * Cons: Requires an external library (lodash), has a learning curve for advanced users. **Library usage** In this benchmark, the lodash library is used in two test cases: * `Array.prototype.some()` using `_.some(a, ['a', 'bc'])` * `lodash.some()` using `var b = _.some(a, ['a', 'bc'])` Lodash provides a set of functional programming utilities, including filtering functions like `some()`. The `_` notation is used to access these utility functions. **Special JS feature or syntax** None of the test cases use any special JavaScript features or syntax that would require explanation beyond the basics of array methods and lodash usage.
Related benchmarks:
native find vs lodash _.find..
array find vs _.find vs _.find (Array) vs _.find (Object)
native find vs lodash _.find_fork
Compare prototype.find vs lodash/find
Comments
Confirm delete:
Do you really want to delete benchmark?