Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array includes lodash vs vanilla JS
(version: 0)
Comparing performance of:
_.includes vs array.includes
Created:
3 years ago
by:
Registered User
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.js"></script>
Script Preparation code:
var primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,97]
Tests:
_.includes
_.includes(primes, 47)
array.includes
primes.includes(47)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.includes
array.includes
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.6 Safari/605.1.15
Browser/OS:
Safari 18 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.includes
34023300.0 Ops/sec
array.includes
68051744.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark. **Benchmark Purpose** The benchmark is designed to compare the performance of two approaches: using Lodash's `_.includes` method and the vanilla JavaScript `Array.includes` method. The purpose is to measure which approach is faster for checking if a value exists in an array. **Options Compared** There are two options being compared: 1. **Lodash's _.includes**: This method is part of the popular Lodash library, which provides a collection of utility functions for functional programming tasks. In this case, it's used to check if a value (47) exists in the `primes` array. 2. **Vanilla JavaScript Array.includes**: This is a native JavaScript method that checks if a value exists in an array. **Pros and Cons** Here are some pros and cons of each approach: * **Lodash's _.includes**: + Pros: - More readable code, as it follows the functional programming style. - Can be more efficient for large arrays, since Lodash is optimized for performance. + Cons: - Requires including an additional library (Lodash), which may add overhead. - May have a steeper learning curve due to its functional programming nature. * **Vanilla JavaScript Array.includes**: + Pros: - No additional library needed, making it simpler and faster to use. - More familiar interface for developers who are already comfortable with JavaScript. + Cons: - May be less readable or more cumbersome for certain use cases, especially those involving functional programming. **Library and Its Purpose** Lodash is a popular utility library that provides a wide range of functions for various tasks, including: * Array manipulation (e.g., `_.includes`, `_.map`, `_filter`) * String manipulation (e.g., `_.string.startsWith`, `_string.endsWith`) * Object manipulation (e.g., `_.object.create`, `_object.get`) * Functional programming helpers (e.g., `_.curry`, `_partial`) Lodash's primary purpose is to provide a set of reusable functions that can simplify common tasks, making development faster and more efficient. **Special JS Feature/Syntax** There is no special JavaScript feature or syntax being tested in this benchmark. The code only uses standard JavaScript features and syntax. **Alternatives** If you want to explore alternative approaches for this specific use case, here are a few options: * Using a different library like `lodash-es` (a subset of Lodash that includes most of the functionality but with a smaller footprint). * Implementing your own `Array.includes` method using a loop or recursion. * Using a custom implementation using bitwise operations to check if an element exists in an array. Keep in mind that each alternative will have its own pros and cons, and some may be more suitable for specific use cases or performance requirements.
Related benchmarks:
array includes
array includes 2
array includes ramda lodash
test js includes and some
Comments
Confirm delete:
Do you really want to delete benchmark?