Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Difference between lists vs filtering on property
(version: 0)
Comparing performance of:
2 lists, difference between lists vs 1 list, filtering on selected property
Created:
2 years ago
by:
Registered User
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 allItems = Array(1000).fill().map((_, i) => ({ id: i, selected: i % 2 == 0 })); var selectedItems = allItems.filter((_, i) => i % 2 == 0);
Tests:
2 lists, difference between lists
const newListDiff = _.differenceWith(allItems, selectedItems, _.isEqual); console.log({newListDiff})
1 list, filtering on selected property
const newListFilter = allItems.filter(item => !item.selected); console.log({newListFilter});
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
2 lists, difference between lists
1 list, filtering on selected property
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 break down the benchmark and its test cases. **Benchmark Overview** The benchmark measures the performance of two approaches to achieve a similar result: 1. Using `_.differenceWith` from Lodash to find the difference between two lists (`allItems` and `selectedItems`). 2. Filtering an array directly using the `filter` method with a callback function that checks if an item's `selected` property is false. **Options Compared** The benchmark compares two options: 1. Using `_.differenceWith` from Lodash, which returns a new array containing elements that are present in `allItems`, but not in `selectedItems`, and vice versa. 2. Filtering an array directly using the `filter` method with a callback function that checks if an item's `selected` property is false. **Pros and Cons of Each Approach** 1. **_.differenceWith (Lodash)**: * Pros: + More explicit and readable code + Can handle more complex comparison logic (e.g., using different comparison functions) + Returns a new array, avoiding modifying the original arrays. * Cons: + May be slower due to the overhead of creating and using Lodash functions. + Requires an additional library dependency (Lodash). 2. **Filtering with `filter`**: * Pros: + Faster execution, as it uses a built-in array method + No additional library dependencies required * Cons: + Code may be less readable and more verbose due to the need for callback functions. + May modify the original arrays (depending on the implementation). **Library: Lodash** The benchmark uses Lodash version 4.17.4, which provides the `_.differenceWith` function. Lodash is a popular utility library for JavaScript that provides a collection of functional programming helpers. **Special JS Feature/Syntax: None** There are no special JavaScript features or syntax used in this benchmark beyond standard ES6+ language features and Lodash's `_.differenceWith` function. **Other Alternatives** If you're interested in alternative approaches, consider the following: 1. Using `Array.prototype.filter()` with a callback function that checks if an item's `selected` property is false. 2. Using a library like `pmap` or `fast-est` to compare arrays and measure performance. 3. Implementing your own custom implementation using JavaScript loops and conditional statements. Keep in mind that the best approach may depend on specific requirements, such as performance, code readability, or library dependencies.
Related benchmarks:
Array.prototype.filter vs Lodash filter
Filter: Lodash 2 vs Native
Filter: Lodash vs Native - same filter
Array.prototype.filter vs Lodash filter (Even Numbers)
Array.prototype.filter vs Lodash filter Clone Test
Comments
Confirm delete:
Do you really want to delete benchmark?