Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array includes
(version: 0)
Comparing performance of:
_.includes vs array.includes
Created:
7 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(79)
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:
2 years ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 17 on iOS 17.5
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.includes
5948375.5 Ops/sec
array.includes
11205820.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested, compared, and the pros/cons of each approach. **Benchmark Definition** The benchmark defines two test cases: 1. `_.includes(primes, 47)`: This is a microbenchmark that tests the performance of the Lodash library's `_.includes` function. 2. `primes.includes(79)`: This is another test case that compares the performance of the built-in array method `includes()` with the `_.includes` function from Lodash. **Script Preparation Code** The script preparation code defines a JavaScript array `primes` and assigns it to a variable: ```javascript 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]; ``` This array is used in both test cases. **Html Preparation Code** The HTML preparation code includes a link to load the Lodash library: ```javascript <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"></script> ``` This library provides the `_.includes` function used in one of the test cases. **Options Compared** The two test cases compare two different approaches to check if an element exists in an array: 1. **Lodash's _.includes**: This method uses a binary search algorithm to find the index of the specified value in the array. 2. **Built-in Array includes():**: This method uses a linear search algorithm to iterate through the elements of the array until it finds the specified value. **Pros and Cons** Here are some pros and cons of each approach: * Lodash's _.includes: + Pros: More efficient for large arrays, especially if the array is sorted. + Cons: Adds an external dependency (Lodash), which may not be desirable in all cases. * Built-in Array includes(): + Pros: No external dependencies required, easy to implement. + Cons: Less efficient than _.includes for large arrays. **Special JS Features/Syntax** There are no special JavaScript features or syntax used in this benchmark. The focus is on comparing the performance of two different approaches to check if an element exists in an array. **Other Alternatives** If you want to test other approaches, you could consider using: * Other libraries like `lodash-es` (a smaller and more modern version of Lodash) or `ramda`. * Built-in methods like `indexOf()`, `includes()`, or `some()` with a custom callback function. * Custom implementation using loops or recursion. Keep in mind that the choice of approach depends on your specific use case, performance requirements, and personal preferences.
Related benchmarks:
array includes 2
array includes ramda lodash
test js includes and some
array includes lodash vs vanilla JS
Comments
Confirm delete:
Do you really want to delete benchmark?