Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash.intersection vs Vanilla JS
(version: 0)
Comparing performance of:
lodash vs vanilla js
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Tests:
lodash
const a = [2, 1]; const b = [2, 3]; const result = _.intersection(a, b);
vanilla js
const a = [2, 1]; const b = [2, 3]; const intersection = (arr, ...args) => arr.filter(item => args.every(arr => arr.includes(item))) const result = intersection(a, b);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash
vanilla js
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/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash
4949399.0 Ops/sec
vanilla js
47151260.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark and explain what's being tested, compared, and other considerations. **Benchmark Overview** The benchmark compares two approaches to find the intersection of two arrays: one using Lodash (`lodash`) and another written in vanilla JavaScript (`vanilla js`). **What is tested?** * **Lodash**: The `intersection` function from Lodash is being used to find the common elements between two arrays. * **Vanilla JavaScript**: A custom implementation of the intersection logic, without any external libraries. **Options compared** The benchmark compares two options: 1. **Lodash**: Using a library that provides a pre-built `intersection` function. 2. **Vanilla JavaScript**: Writing a custom implementation from scratch. **Pros and Cons of each approach** **Lodash** Pros: * Faster execution: Lodash is optimized for performance and provides a well-tested, battle-proven algorithm. * Less boilerplate code: You don't need to write the intersection logic yourself. Cons: * External dependency: The benchmark relies on Lodash being loaded from a CDN, which might affect performance or cause issues with some environments. * Additional overhead: Including an external library adds a small overhead due to HTTP requests and loading times. **Vanilla JavaScript** Pros: * No dependencies: This approach doesn't rely on any external libraries, making it more self-contained. * Control over implementation: You have complete control over the algorithm used and can optimize it for your specific use case. Cons: * More boilerplate code: You need to write the intersection logic yourself, which can be time-consuming. * Potential performance issues: Without optimization, a custom implementation might not perform as well as Lodash's optimized version. **Library and its purpose** Lodash is a popular JavaScript utility library that provides a wide range of functions for various tasks, including array operations. In this case, the `intersection` function is used to find the common elements between two arrays. **Special JS feature or syntax (not applicable)** There are no special features or syntaxes being tested in this benchmark. The focus is on comparing the performance and implementation differences between Lodash's pre-built function and a custom vanilla JavaScript implementation. **Other alternatives** If you're interested in exploring other approaches, here are some alternatives: * Using `Array.prototype.filter()` with `includes()`: This approach uses the `filter()` method to create a new array containing only elements that meet the condition (i.e., being included in both arrays). * Utilizing a different library or framework: Depending on your specific needs and preferences, you might consider using other libraries or frameworks for array operations, such as `lodash-es` (a subset of Lodash with ES6+ support) or `moment.js` for date-related tasks. * Implementing a custom algorithm from scratch: You can explore optimizing a basic intersection logic to achieve the best performance for your specific use case. Keep in mind that each approach has its trade-offs, and the choice ultimately depends on your project's requirements, constraints, and your team's expertise.
Related benchmarks:
Lodash: difference vs intersection
Array Intersection vs. Set Intersection vs. Lodash
Lodash Intersection vs. ES6 includes
Array Intersection vs. Set Intersection vs. Lodash part 5
Array Intersection vs. Set Intersection vs. Lodash part 3 mix
Comments
Confirm delete:
Do you really want to delete benchmark?