Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash includes vs has
(version: 0)
Comparing performance of:
includes vs has
Created:
3 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:
var array = ['banana', 'sausage', 'jesus']
Tests:
includes
_.includes(array, 'sausage')
has
_.has(array, 'sausage')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
includes
has
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
28607234.0 Ops/sec
has
28354406.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain what's being tested in the provided benchmark. The test case uses two functions from the Lodash library: `_.includes()` and `_.has()`. These functions are used to check if an element exists within an array. **What are these functions doing?** `_.includes()` checks if a value (in this case, `'sausage'`) exists in the given array (`array`). It returns a boolean indicating whether the value is present in the array or not. `_.has()`, on the other hand, checks if an object has a specific property. In this test case, it's checking if the array `array` has a property with the value `'sausage'`. **Options being compared** In this benchmark, two options are being compared: 1. **Lodash**: The Lodash library is being used as a baseline for both tests. This means that the benchmark is comparing the performance of `_.includes()` and `_.has()` against each other, using the same library. 2. **Native JavaScript**: In addition to the Lodash implementation, the benchmark also checks the native JavaScript implementation (`array.includes()`) and its equivalent for objects (using the `in` operator). **Pros and cons** Using a library like Lodash can provide benefits such as: * Code readability: The functions are often more concise and expressive than their native counterparts. * Reusability: Lodash provides a set of utility functions that can be reused in multiple contexts. However, using a library also has some drawbacks: * Overhead: Including an external library can introduce additional overhead due to the need for loading and parsing the code. * Dependence on the library: The performance of the benchmark may be affected if the user does not have the Lodash library installed or is using an outdated version. Using native JavaScript functions, such as `array.includes()` and `in`, has some advantages: * No overhead: These functions do not require loading or parsing any external code. * Built-in support: Native functions are typically more efficient and have better support for various platforms and browsers. However, native functions may also have some drawbacks: * Less readable code: The syntax of these functions can be less concise and expressive than their library counterparts. * Limited reusability: These functions are often specific to a particular data structure (arrays or objects) and may not be as versatile as library functions. **Other considerations** In this benchmark, it's worth noting that the Lodash implementation is being compared against its native JavaScript counterpart. This allows for a more direct comparison between the two approaches. Additionally, the use of `_.has()` in the test case is interesting because it checks if an object has a specific property, whereas `_.includes()` only checks for existence within an array. **Alternatives** Some alternative benchmarking scenarios could include: * Comparing different implementations of Lodash functions (e.g., using a different version or a custom implementation). * Checking the performance of native JavaScript functions against each other (e.g., comparing `array.includes()` to `array.indexOf()`). * Including additional data structures, such as sets or maps, in the benchmark. These alternatives could provide more insights into the performance characteristics of different approaches and help identify potential bottlenecks or areas for optimization.
Related benchmarks:
IndexOf vs Includes vs lodash includes
IndexOf vs Includes vs lodash includes vs manual check
IndexOf vs Includes vs lodash includes test2
IndexOf vs Includes vs lodash includes for string
Comments
Confirm delete:
Do you really want to delete benchmark?