Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Replace _.intersection
(version: 0)
Comparing performance of:
Lodash vs Native vs ES6
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Tests:
Lodash
console.log(_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]))
Native
var arrays = [[1, 2, 3], [101, 2, 1, 10], [2, 1]]; console.log(arrays.reduce(function(a, b) { return a.filter(function(value) { return b.includes(value); }); }));
ES6
let arrays = [[1, 2, 3], [101, 2, 1, 10], [2, 1]]; console.log(arrays.reduce((a, b) => a.filter(c => b.includes(c))));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash
Native
ES6
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):
Let's dive into the world of JavaScript microbenchmarks! **What is tested?** The provided JSON represents a benchmark test case on MeasureThat.net, which compares three approaches to find the intersection of two arrays in JavaScript: 1. **Lodash**: Using the `_.intersection` function from the Lodash library. 2. **Native JavaScript**: Implementing the intersection logic natively without any external libraries. 3. **ES6 Syntax**: Utilizing the new array methods (filter(), includes()) introduced in ECMAScript 2015 (ES6). **Options compared** The three options are compared to determine which approach is faster. **Pros and Cons of each approach:** 1. **Lodash**: * Pros: Easy to use, concise code, well-tested library. * Cons: Additional dependency, slower due to library overhead. 2. **Native JavaScript**: * Pros: Fastest execution, no dependencies or overhead. * Cons: More verbose code, requires manual implementation of logic. 3. **ES6 Syntax**: * Pros: Concise and readable code, well-suited for modern JavaScript applications. * Cons: May be slower than native implementation due to method overhead. **Library used - Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for common tasks, such as array manipulation, string manipulation, and more. In this case, `_.intersection` is used to find the intersection of two arrays. Lodash's performance can vary depending on the specific use case, but in general, it's a convenient way to simplify code. **Special JS feature or syntax - None** There are no special JavaScript features or syntaxes used in these benchmark test cases. **Benchmark result analysis** The latest benchmark results show that: * **Native JavaScript** is the fastest approach, with an average of 931055.6875 executions per second. * **ES6 Syntax** is slower than native implementation but still relatively fast, averaging 1030275.4375 executions per second. * **Lodash** is the slowest approach, averaging 1041534.5625 executions per second. These results suggest that when performance is crucial, using native JavaScript code can be a good choice. However, if readability and conciseness are more important, ES6 syntax might be a better option. **Other alternatives** For this specific benchmark, the alternatives to these three approaches could include: * Using other libraries or frameworks that provide array manipulation functions (e.g., `Array.prototype.filter()`). * Implementing custom algorithms for finding intersections. * Utilizing WebAssembly or native modules for performance-critical code. * Exploring alternative JavaScript engines or implementations (e.g., V8, SpiderMonkey) to see if they offer better performance.
Related benchmarks:
Lodash compact
Lodash replace
isEmpty vs. vanilla
Lodash Intersection vs. ES6 includes
Comments
Confirm delete:
Do you really want to delete benchmark?