Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test performance
(version: 18)
Comparing performance of:
Set vs Lodash group vs Map
Created:
4 years ago
by:
Registered User
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:
var permissionList = Array.from({ length: 1000000 }, (i, j) => ({ app: "oxygen", resource: "user", action: "profile", group: "Group" + j, isAllowed: true })); var payload = { "app": "oxygen", "resource": "user", "action": "profile", "groups": Array.from({ length: 110000 }, (i, j) => "Group" + j), "isAllowed": false };
Tests:
Set
const filter = permissionList .filter(permission => permission.action === payload.action && permission.resource === payload.resource) .map(permission => permission.group); const groupSet = new Set(filter); const missingGroups = payload.groups.filter(group => !groupSet.has(group));
Lodash group
const filter = permissionList .filter(permission => permission.action === payload.action && permission.resource === payload.resource); const groupSet = _.groupBy(filter, 'group'); const missingGroups = payload.groups.filter(group => !groupSet[group]);
Map
const groupSet = {}; permissionList.forEach(permission => { groupSet[permission.group] = permission.action === payload.action && permission.resource === payload.resource; }); const missingGroups = payload.groups.filter(group => !groupSet[group]);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Set
Lodash group
Map
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 on MeasureThat.net. **What is tested?** The provided benchmark tests three different approaches to filter and group an array of objects: 1. **Set**: Using the built-in `Set` data structure in JavaScript, filtering and mapping the `permissionList` array. 2. **Lodash group**: Utilizing the Lodash library to group the filtered elements by their "group" property. 3. **Map**: Creating a map (an object where keys are unique values) to store the results of the filtering process. **Options compared** The three options are compared in terms of performance, specifically the number of executions per second on a Chrome 91 browser on a Mac OS X 10.15.7 desktop platform. **Pros and cons of each approach:** 1. **Set**: * Pros: Efficient use of built-in data structure, simple to implement. * Cons: May not be suitable for large datasets or complex filtering scenarios due to its inherent limitations (e.g., no sorting or reversing). 2. **Lodash group**: * Pros: Provides a robust and flexible way to group elements, with support for various iteration methods. * Cons: Adds external library dependency, which may incur overhead. 3. **Map**: * Pros: Allows for efficient key-based lookups and can be used in conjunction with other data structures. * Cons: May not be the most suitable choice for this specific use case due to its more complex implementation requirements. **Library usage** The benchmark uses Lodash, a popular JavaScript library for functional programming utilities. Specifically, it relies on the `_.groupBy` function to group the filtered elements by their "group" property. **Special JS features/syntax** None of the individual test cases utilize any special JavaScript features or syntax that would require additional explanation. The focus is on comparing the performance of different filtering and grouping approaches. **Other alternatives** If you're interested in exploring alternative approaches, some options might include: * Using a custom implementation with a queue-based or stack-based approach * Leveraging libraries like Moment.js for date-related calculations (not applicable to this specific benchmark) * Employing WebAssembly (WASM) or other low-level optimization techniques * Comparing the performance of different JavaScript engines or versions Keep in mind that these alternatives might not be directly comparable to the original benchmark, and their inclusion would depend on the specific requirements and goals of the project. I hope this explanation helps you understand the details of the provided benchmark!
Related benchmarks:
Checks if value is an object
_.map vs. array.map for object
aadasdsa
lodash groupBy vs Array.reduce vs Array.group 100k
lodash groupBy vs Array.reduce group by 100k
Comments
Confirm delete:
Do you really want to delete benchmark?