Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array includes 2
(version: 0)
Comparing performance of:
_.includes vs array.includes
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.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, 79)
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:
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):
I'll break down the benchmark definition, test cases, and their results to explain what's being tested. **Benchmark Definition** The provided JSON represents a JavaScript microbenchmark that tests two different approaches for checking if an element exists in an array: using the `_.includes` method from the Lodash library and the built-in `array.includes` method. **Script Preparation Code** The script preparation code defines a constant `primes` which is an array of prime numbers. This array will be used as the test data for both benchmarks. **Html Preparation Code** The HTML preparation code includes a reference to the Lodash JavaScript library, version 4.17.11, using a CDN. This library provides the `_.includes` method that will be tested. **Test Cases** There are two individual test cases: 1. **_.includes** * Benchmark Definition: `_.includes(primes, 79)` * Test Name: `_.includes` 2. **array.includes** * Benchmark Definition: `primes.includes(79)` * Test Name: `array.includes` **Pros and Cons of Different Approaches** 1. **_.includes (Lodash)**: * Pros: + Provides a standardized way to check for array element existence. + Might be optimized by Lodash for performance. * Cons: + Adds an extra dependency on the Lodash library. 2. **array.includes**: * Pros: + Native JavaScript method, no additional dependencies required. + Fast and lightweight. * Cons: + May not provide a standardized way to check for array element existence (implementation details vary across browsers). + Might be less optimized than _.includes. **Library: Lodash** Lodash is a popular utility library for JavaScript that provides a wide range of functions, including `_.includes`. It's designed to make common tasks easier and more efficient. In this benchmark, the `_.includes` method is used to check if an element exists in the `primes` array. **Special JS Feature/Syntax** There are no special JavaScript features or syntaxes mentioned in the provided code snippets. The tests only rely on standard JavaScript array methods. **Other Alternatives** If you're interested in exploring alternative approaches for checking if an element exists in an array, here are a few options: * Using `Array.prototype.find()` and `===`: ```javascript primes.includes(79) === primes.find((x) => x === 79); ``` * Using `forEach()` and checking the index: ```javascript let found = false; for (let i = 0; i < primes.length; i++) { if (primes[i] === 79) { found = true; break; } } primes.includes(79) === found; ``` Keep in mind that these alternatives may have different performance characteristics and are not as concise or readable as the original methods.
Related benchmarks:
array includes
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?