Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash difference vs JS filter and includes with big array
(version: 0)
Comparing performance of: Lodash difference vs JS Filter and includes with big array
Comparing performance of:
Lodash difference vs JS Filter and includes
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>
Script Preparation code:
function makeid(length) { var result = ''; var characters = 'abcdefghijklmnopqrstuvwxyz'; var charactersLength = characters.length; for ( var i = 0; i < length; i++ ) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } var array1 = Array.from({length: 10000}, () => makeid(5)); var array2 = Array.from({length: 10000}, () => makeid(5));
Tests:
Lodash difference
filteredArray = _.difference(array1, array2);
JS Filter and includes
filteredArray = array1.filter((arr) => !array2.includes(arr));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash difference
JS Filter and includes
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0
Browser/OS:
Firefox 121 on Ubuntu
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash difference
604.7 Ops/sec
JS Filter and includes
3.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what is being tested in this benchmark. **Benchmark Definition** The test aims to compare the performance of two approaches: 1. **Lodash difference**: Using the `_.difference` function from the Lodash library, which returns the difference between two arrays. 2. **JS Filter and includes**: Using the `filter()` method with a callback function that checks if an element is not included in another array using the `includes()` method. **Options Compared** The two options being compared are: * Lodash's `_.difference` function, which uses a specialized algorithm to find the differences between two arrays. * A standard JavaScript approach using `filter()` and `includes()`, which can be slower due to the overhead of creating a new array for filtering. **Pros and Cons** **Lodash difference:** Pros: * Optimized for performance, using a specialized algorithm that takes advantage of array properties. * Provides a simple and concise way to find differences between arrays. Cons: * Requires including an additional library (Lodash) in the test environment. * May not be suitable for all use cases or libraries. **JS Filter and includes:** Pros: * Does not require any external libraries, making it easier to set up and run. * Can be used with a wide range of libraries and frameworks. Cons: * May be slower due to the overhead of creating a new array for filtering. * Requires more boilerplate code compared to Lodash's `_.difference` function. **Other Considerations** The test also considers device platform, operating system, and browser versions, which can affect performance. The benchmark measures executions per second, providing insight into the relative performance of each approach across different devices and browsers. **Library and Purpose** * **Lodash**: A popular JavaScript utility library that provides a wide range of functions for tasks like array manipulation, string processing, and more. + Purpose: Simplify common programming tasks and provide optimized solutions. **Special JS Feature or Syntax** This benchmark does not explicitly use any special JavaScript features or syntax. However, the `includes()` method is used in the second test case, which is a relatively modern feature introduced in ECMAScript 2015 (ES6).
Related benchmarks:
Array.prototype.filter vs Lodash filter
Array.prototype.filter vs Lodash without
Array.prototype.filter vs Lodash.without
Array.prototype.filter vs Lodash filter (Even Numbers)
Array.prototype.filter vs Lodash without 2
Comments
Confirm delete:
Do you really want to delete benchmark?