Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Js array intersection
(version: 0)
Comparing performance of:
js vs lodash
Created:
3 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:
js
var a = ['This is not Vietnam, this is bowling!', 'There are rules!', 'Dude.', 'It really tied the room together.'] var b = ['This is not Vietnam, this is bowling!', 'Nihilists', 'Dude.',] var c = a.filter(e=>b.includes(e))
lodash
var a = ['This is not Vietnam, this is bowling!', 'There are rules!', 'Dude.', 'It really tied the room together.'] var b = ['This is not Vietnam, this is bowling!', 'Nihilists', 'Dude.',] var c = _.intersection(a, b)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
js
lodash
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0
Browser/OS:
Firefox 124 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
js
13916373.0 Ops/sec
lodash
4373309.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided benchmark definition and test cases measure the performance of finding the intersection between two arrays, with or without using the Lodash library. **Script Preparation Code** The script preparation code for this benchmark is: ```html <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> ``` This code includes the Lodash library in the test environment, which provides a utility function `intersection` that can be used to find the intersection between two arrays. **Test Cases** There are two individual test cases: 1. **js**: This test case uses the native JavaScript implementation of array intersection without using any external libraries. ```javascript var a = ['This is not Vietnam, this is bowling!', 'There are rules!', 'Dude.', 'It really tied the room together.']; var b = ['This is not Vietnam, this is bowling!', 'Nihilists', 'Dude.,']; var c = a.filter(e => b.includes(e)); ``` 2. **lodash**: This test case uses the `intersection` function from Lodash to find the intersection between two arrays. ```javascript var a = ['This is not Vietnam, this is bowling!', 'There are rules!', 'Dude.', 'It really tied the room together.']; var b = ['This is not Vietnam, this is bowling!', 'Nihilists', 'Dude.,']; var c = _.intersection(a, b); ``` **Options Compared** The two test cases compare the performance of: * Native JavaScript implementation vs. using Lodash library for array intersection. **Pros and Cons** * **Native JavaScript Implementation**: + Pros: No dependencies on external libraries, potentially faster execution. + Cons: May be slower due to the overhead of native JavaScript operations. * **Lodash Library**: + Pros: Faster execution due to optimized implementation by Lodash team, less error-prone code. + Cons: Requires an additional dependency (the Lodash library), may introduce performance overhead. **Other Considerations** * The use of `filter` and `includes` methods in the native JavaScript implementation may be slower than using a specialized intersection function like `intersection` from Lodash. * The test cases do not account for variations in array sizes, data distributions, or other factors that might affect performance. **Alternatives** If you wanted to add more test cases, you could consider: 1. Using different data structures (e.g., sets, trees) instead of arrays. 2. Using different languages or implementations (e.g., Node.js, WebAssembly). 3. Accounting for variations in input data or array sizes. 4. Adding additional dependencies (e.g., parallel processing, caching).
Related benchmarks:
compact function
Lodash compact
lodash slice
Lodash replace
_.compact vs array.filter
Comments
Confirm delete:
Do you really want to delete benchmark?