Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
uniqBy vs stringify performance
(version: 0)
lodash vs javascript
Comparing performance of:
lodash vs javascript
Created:
5 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');
javascript
const uniqueArray = a => [...new Set(a.map(o => JSON.stringify(o)))].map(s => JSON.parse(s)); uniqueArray(data)
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:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash
10265506.0 Ops/sec
javascript
835110.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON benchmark definition and explain what is tested, compared, and discussed. **Benchmark Definition** The benchmark tests two approaches to removing duplicates from an array while preserving order: 1. **Lodash**: The first approach uses Lodash's `uniqBy` function, which removes duplicate elements based on a specified key (in this case, `'a'`). Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks like array manipulation, string manipulation, and more. 2. **JavaScript (Custom Implementation)**: The second approach uses a custom implementation in plain JavaScript to achieve the same result. This implementation uses `Array.prototype.map()` to create a new array with duplicate elements removed. **Comparison** The benchmark compares the performance of these two approaches: * Lodash's `uniqBy` function * A custom implementation using plain JavaScript **Pros and Cons** **Lodash (`uniqBy`)** Pros: * Well-tested and widely used, which can lead to better performance and fewer bugs. * Provides a convenient way to perform common tasks like array manipulation. Cons: * May incur additional overhead due to the use of an external library. * Can be slower than custom implementations for simple tasks. **Custom JavaScript Implementation** Pros: * Can be optimized for specific use cases or platforms, potentially leading to better performance. * Eliminates the need for an external library, reducing overhead and potential compatibility issues. Cons: * May require more manual effort to implement and maintain. * May not be as performant as well-written, optimized libraries like Lodash. **Other Considerations** The benchmark also considers factors such as device platform (Desktop), operating system (Mac OS X 10.15.7), browser version (Chrome 112), and executions per second. **Library - Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks like array manipulation, string manipulation, and more. Its `uniqBy` function is specifically designed to remove duplicate elements based on a specified key, making it an attractive choice for this benchmark. **Special JS Feature/Syntax (None)** There are no special JavaScript features or syntax used in this benchmark. **Alternatives** Some alternatives to Lodash's `uniqBy` function include: * Using the built-in `Set` data structure in combination with `Array.prototype.filter()` and `JSON.stringify()`. * Utilizing a library like `lodash-es` (ES6+ version of Lodash) or `lodash-clampMapKeys` for more fine-grained control over the key function. * Implementing a custom solution using a different approach, such as sorting the array by the specified key and then removing duplicates. Keep in mind that these alternatives may have their own pros and cons, depending on the specific requirements of your use case.
Related benchmarks:
uniqBy performance
uniqBy performance ttt
uniqBy performance lodash vs native
uniqBy performance and map
Comments
Confirm delete:
Do you really want to delete benchmark?