<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"></script>
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]
_.includes(primes, 47)
primes.includes(47)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
_.includes | |
array.includes |
Test name | Executions per second |
---|---|
_.includes | 2905180.0 Ops/sec |
array.includes | 12609694.0 Ops/sec |
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:
primes
array.Pros and Cons
Here are some pros and cons of each approach:
Library and Its Purpose
Lodash is a popular utility library that provides a wide range of functions for various tasks, including:
_.includes
, _.map
, _filter
)_.string.startsWith
, _string.endsWith
)_.object.create
, _object.get
)_.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:
lodash-es
(a subset of Lodash that includes most of the functionality but with a smaller footprint).Array.includes
method using a loop or recursion.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.