Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
uniqBy performance ttt
(version: 0)
lodash vs javascript
Comparing performance of:
lodash vs javascript
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script>https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.core.js</script>
Script Preparation code:
var data = [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}, {a: 6}, {a: 7}, {a: 8}, {a: 1}];
Tests:
lodash
_.uniqBy(data, a => a.a + 'aaa');
javascript
const sortBy = (key) => { return (a, b) => (a[key] > b[key]) ? 1 : (b[key] > a[key] ? -1 : 0); }; const uniqBy = (arr, a) => { arr.sort(sortBy(a)); const arr1 = []; arr1.push(arr[0]); for (let index = 1; index < arr.length; index++) { if (arr[index-1] && arr[index -1].a !== arr[index].a) { arr1.push(arr[index]); } } return arr1; } uniqBy(data, 'a')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash
javascript
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 benchmark analysis. **What is being tested?** The provided JSON represents a JavaScript microbenchmark test case that compares the performance of two approaches: using Lodash (`_.uniqBy`) and implementing it from scratch in JavaScript (`uniqBy` function). The test data consists of an array of objects with a unique identifier (`a`) used as the key for uniqueness. **Options compared** The two options being compared are: 1. **Lodash' `_.uniqBy`**: A utility function from the Lodash library that removes duplicates based on a given key, while preserving order. 2. **Custom JavaScript implementation of `uniqBy`**: A self-implemented function that uses sorting to remove duplicates. **Pros and Cons** ### Lodash' `_.uniqBy` Pros: * **Convenience**: Lodash provides a well-tested and widely used implementation of unique-by-attribute functionality, making it easy to reuse. * **Efficient**: Optimized for performance and optimized for common use cases. Cons: * **Additional dependency**: Requires including the Lodash library in the test environment, which may add overhead or dependencies not present in a pure JavaScript context. * **Loss of control**: The implementation details are hidden from view, making it harder to understand the underlying logic and potentially limiting customization. ### Custom JavaScript implementation Pros: * **Control and understanding**: By implementing the algorithm manually, developers can gain a deeper understanding of the code's behavior and make targeted optimizations. * **No dependencies**: No external libraries or dependencies need to be included, reducing overhead and complexity. Cons: * **More complex**: The custom implementation requires manual handling of sorting, duplicates, and edge cases, which can add complexity. * **Potential performance issues**: Without optimization, the custom implementation may not perform as efficiently as Lodash' optimized version. **Library and its purpose** The `lodash` library is a popular collection of utility functions for JavaScript, providing a wide range of algorithms for common tasks. In this case, `_uniqBy` is used to remove duplicates from an array based on a specific key, while preserving the original order. **Special JS feature or syntax (none mentioned)** There are no special JavaScript features or syntaxes being tested in these benchmark cases. **Other alternatives** If you were to compare other approaches for removing duplicates by attribute, some alternatives might include: * Using `Set` and filtering based on the unique attribute * Utilizing a map-based approach with a single pass through the data * Implementing a custom sorting algorithm with a more efficient comparison function Keep in mind that each of these alternatives would require trade-offs between performance, memory usage, and readability. I hope this analysis provides valuable insights into the benchmark test cases!
Related benchmarks:
uniqBy performance
uniqBy vs stringify performance
uniqBy performance lodash vs native
uniqBy performance and map
Comments
Confirm delete:
Do you really want to delete benchmark?