Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native find vs lodash _.find but for 100k elements
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
array find vs _.find
Created:
6 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.11/lodash.core.js"></script>
Script Preparation code:
function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; //Максимум не включается, минимум включается } var users = Array.from({ length: 100000 }, item => ({ age: getRandomInt(18, 65), user: ['joey', 'ross', 'chandler'][getRandomInt(0, 2)] }))
Tests:
array find
// Native users.find(function (o) { return o.age < 40; })
_.find
_.find(users, function (o) { return o.age < 40; })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
array 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 provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark compares two approaches to find an element in an array: using JavaScript's native `Array.prototype.find()` method versus Lodash's `_` utility function, specifically `_find()`. The test case uses a dataset of 100,000 users with random ages and user roles. **Options Compared** There are two options being compared: 1. **Native `Array.prototype.find()`**: This method returns the first element in an array that satisfies the provided condition. In this case, it's used to find the user with an age less than 40. 2. **Lodash `_find()`**: This function takes a dataset (in this case, the `users` array) and a callback function as arguments. The callback function is executed for each element in the dataset, and when it returns `true`, that value is returned. **Pros and Cons of Each Approach** 1. **Native `Array.prototype.find()`**: * Pros: Native implementation means better performance and lower memory usage. * Cons: Requires a strict condition to return the desired result (i.e., `return o.age < 40`). 2. **Lodash `_find()`**: * Pros: Easier to use, as it abstracts away the iteration logic and returns the first matching element. * Cons: Adds an extra dependency on Lodash, which may slow down the benchmark. **Library Used** In this case, Lodash is used as a utility library. Its purpose is to provide a set of reusable functions for tasks such as array manipulation, string manipulation, and more. In this specific case, `_find()` is used to find an element in an array that satisfies a given condition. **Special JS Feature or Syntax** There are no special JavaScript features or syntaxes being used in this benchmark. It's standard JavaScript code. **Other Considerations** When writing benchmarks like this one, it's essential to consider the following factors: * **Independence**: Each test case should be independent and not rely on previous results. * **Consistency**: The benchmarking process should be consistent, using the same dataset and execution environment. * **Scalability**: The benchmark should be able to handle large datasets and varying hardware configurations. **Alternatives** Other alternatives for finding an element in an array include: * Using `forEach()` with a callback function * Using `map()` followed by `find()` * Using a custom loop or recursive approach However, these approaches may have different performance characteristics compared to the native `Array.prototype.find()` method and Lodash `_find()` function.
Related benchmarks:
native find vs lodash _.find
native find vs lodash _.find for object
native find vs lodash _.find aamurray
native find vs lodash _.find_fork
native find vs for..in
Comments
Confirm delete:
Do you really want to delete benchmark?