Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash intersect vs includes
(version: 0)
Comparing performance of:
intersection vs includes
Created:
4 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>
Script Preparation code:
var arr = ['the past','the present','the future','lorem','ipsum','dolor','sit amet']
Tests:
intersection
_.intersection(arr, ['the past'])
includes
_.includes(arr, 'the past')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
intersection
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'd be happy to help you understand the JavaScript microbenchmark on MeasureThat.net. **Overview of the Benchmark** The benchmark compares two operations performed on an array using the Lodash library: `_.intersection(arr, ['the past'])` and `_.includes(arr, 'the past')`. The test case uses a predefined array `arr` containing several strings, including "the past", which is used for both comparisons. **What is being tested?** The benchmark measures the execution time of these two operations on different browsers. Specifically, it compares: 1. **Intersection**: Returns a new array with elements common to both the original array (`arr`) and the specified array (`['the past']`). 2. **Includes**: Returns `true` if the specified value (`'the past'`) is present in the original array (`arr`). **Options compared** The benchmark compares two options: 1. **Lodash library**: The Lodash library provides a set of functions for functional programming, including `intersection` and `includes`. Using this library allows for concise and efficient code. 2. **Native JavaScript implementation**: By not using the Lodash library, the test case relies on native JavaScript implementations of `intersection` and `includes`. **Pros and Cons** Using the Lodash library: Pros: * Provides a concise and readable way to perform complex operations * Reduces boilerplate code * May be faster due to optimized implementations Cons: * Adds dependency on an external library * May increase bundle size Native JavaScript implementation: Pros: * No dependency on external libraries * Lighter bundle size * Can be beneficial for performance-critical code Cons: * Requires more verbose and repetitive code * May lead to less readable and maintainable code **Lodash Library** The Lodash library is a popular utility library for functional programming in JavaScript. It provides a wide range of functions for tasks such as array manipulation, string manipulation, object creation, and more. In this specific case, the `intersection` function returns a new array with elements common to both the original array and the specified array. The `includes` function returns `true` if the specified value is present in the original array. **Other Considerations** When testing performance-critical code, it's essential to consider factors such as: * Cache locality: How well do the different implementations cache data? * Branch prediction: How accurately can branch predictors predict the execution path? * Loop unrolling and parallelization: Are the implementations optimized for loop unrolling and parallelization? **Alternatives** Some alternatives to the Lodash library include: * Underscore.js: Another popular utility library for functional programming in JavaScript. * Ramda: A functional programming library that provides a different set of functions for array manipulation, object creation, and more. * Built-in JavaScript methods: For some operations, built-in JavaScript methods such as `filter()`, `some()`, or `forEach()` can be used instead. Keep in mind that these alternatives may have different performance characteristics, so it's essential to test them thoroughly in your specific use case.
Related benchmarks:
Lodash: difference vs intersection
Lodash: difference vs intersection vs includes
Lodash intersection vs plain js
native intersect vs lodash intersection
Comments
Confirm delete:
Do you really want to delete benchmark?