Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash _.some vs _.includes
(version: 0)
Some vs Includes
Comparing performance of:
some vs Includes
Created:
5 years 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:
function makeid(length) { var result = ''; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var charactersLength = characters.length; for ( var i = 0; i < length; i++ ) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } var a = []; for (let i=0; i<100000; i++){ a.push(makeid(15)); }
Tests:
some
_.some(a, x=>x===a[23424]); _.some(a, x=>x===a[0]); _.some(a, x=>x===a[99999]);
Includes
_.includes(a, a[23424]); _.includes(a, a[0]); _.includes(a, a[99999]);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
some
Includes
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/127.0.0.0 Safari/537.36 SberBrowser/19.0.0.0
Browser/OS:
Chrome 127 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
some
53.2 Ops/sec
Includes
169.5 Ops/sec
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 Definition** The benchmark is comparing the performance of two Lodash functions: `_.some()` and `_.includes()`. The functions are applied to an array `a` that contains 100,000 random strings of length 15. **What's being tested?** * Two options for iterating over arrays: + `_.some()`: This function returns `true` as soon as the condition is met (i.e., one element in the array satisfies the callback). It's a short-circuiting function, meaning it stops searching as soon as it finds a match. + `_.includes()`: This function returns `true` if the array contains an element that matches the provided value. Unlike `_.some()`, it doesn't stop searching once it finds a match; it continues to iterate over all elements. * The pros and cons of these approaches: + `_.some()` is likely to be faster because it uses early termination, which reduces the number of iterations required. However, this also means that if the condition is not met on the first element, the function will still iterate over all 100,000 elements (although in practice, most elements will be skipped). + `_.includes()`, on the other hand, ensures that every element is processed, but it may incur more overhead due to the repeated comparisons. **Library and purpose** * Lodash is a popular JavaScript utility library that provides a wide range of functional programming helpers. In this case, we're using two specific functions: `_.some()` and `_.includes()`. These functions are part of Lodash's collection manipulation module. **Other considerations** * The benchmark uses a fixed-size array to avoid variations in performance caused by changes in memory allocation or garbage collection. * The use of random strings as elements in the array helps to mask any performance differences that might be due to string length or type. * The benchmark is run on multiple executions per second, which provides an estimate of the average execution time. **Alternatives** If you were to write a similar benchmark without using Lodash, you could use vanilla JavaScript implementations for `_.some()` and `_.includes()`. For example: ```javascript function some(arr, callback) { for (let i = 0; i < arr.length; i++) { if (callback(arr[i])) return true; } return false; } function includes(arr, value) { for (let i = 0; i < arr.length; i++) { if (arr[i] === value) return true; } return false; } ``` Keep in mind that these implementations would likely be slower than the Lodash versions, especially for large arrays.
Related benchmarks:
Lodash _.some vs _.includes vs array.find
Lodash difference vs JS filter and includes with big array
Lodash some vs JS some 1
lodash _.some vs Array.some
Comments
Confirm delete:
Do you really want to delete benchmark?