Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.filter with large objects 2
(version: 0)
Testing whether filter an array of large objects is faster is we "index" the objects vs just having an array of large objects.
Comparing performance of:
Filter with indexed identifier vs Filter without index
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js"></script>
Script Preparation code:
var indexedGroupList = Array.from({length: 10000}, () => { var temp_id = Math.floor(Math.random() * 99999999); var temp_group_id = Math.floor(Math.random() * 10); return { "id": temp_id, "group_id": temp_group_id, "post": { "id": temp_id, "group_id": temp_group_id, "name": "Test Name Here", "created_at": 1234871928373, "updated_at": 8471829378473, "is_test": true, "is_valid": false, "description": "this is a long form description text here.", } } }); var groupList = Array.from({length: 10000}, () => { return { "id": Math.floor(Math.random() * 99999999), "group_id": Math.floor(Math.random() * 10), "name": "Test Name Here", "created_at": 1234871928373, "updated_at": 8471829378473, "is_test": true, "is_valid": false, "description": "this is a long form description text here." } });
Tests:
Filter with indexed identifier
_.filter(indexedGroupList, { 'group_id': 4 });
Filter without index
_.filter(groupList, { 'group_id': 4 });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Filter with indexed identifier
Filter without index
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 provided benchmark definition and explain what is being tested. **Benchmark Definition** The benchmark tests two approaches to filtering an array of large objects using the Lodash library: 1. `_.filter(indexedGroupList, { 'group_id': 4 })`: This test uses indexed grouping, where each object in the `indexedGroupList` has a `group_id` property. The filter function is applied to this list with an object specifying only the `group_id` property. 2. `_.filter(groupList, { 'group_id': 4 })`: This test does not use indexed grouping and applies the filter function directly to the `groupList`. **Options Compared** The two tests compare the performance of filtering the array using: * Indexed grouping (`_.filter(indexedGroupList, { 'group_id': 4 })`) * Non-indexed filtering (`_.filter(groupList, { 'group_id': 4 })`) **Pros and Cons of Different Approaches** Indexed grouping can lead to better performance because it allows the engine to use an index to quickly locate matching elements. This approach requires more memory for the object's metadata, but it often results in faster filtering times. Non-indexed filtering relies on a linear search through the array, which can be slower. However, this approach is often simpler and more efficient in terms of memory usage. **Lodash Library** The Lodash library provides the `_.filter()` function used in both tests. The `_.filter()` function takes two arguments: an array and a callback function that determines which elements to include in the resulting array. In this case, the callback function is specified as `{ 'group_id': 4 }`, which means only objects with a `group_id` property equal to 4 will be included. **Special JS Feature or Syntax** There are no special JavaScript features or syntax used in these tests. However, the benchmark definition uses some JavaScript best practices, such as using `Array.from()` to create arrays and object destructuring for better code readability. **Other Alternatives** If you wanted to test a different filtering approach or library, you could consider alternatives like: * Using a custom implementation of the filter function * Testing with different data structures (e.g., linked lists, trees) * Using a different library or framework that provides similar functionality (e.g., `filter()` in Array.prototype) Keep in mind that these alternative tests would require significant changes to the benchmark definition and test cases.
Related benchmarks:
slice vs filter more than 1000
Set vs Filter for unique 40k
slice vs filter (10000000)
Set vs Filter for unique for me
Array.find vs Array.filter on large dataset
Comments
Confirm delete:
Do you really want to delete benchmark?