Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
get uniq values js
(version: 0)
lodash uniqBy vs vanilla js
Comparing performance of:
js vs lodash
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:
js
data.filter((v, i, a) => a.findIndex(t => t.a === v.a) === i)
lodash
_.uniqBy(data, 'a');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
js
lodash
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
gemma2:9b
, generated one year ago):
This benchmark tests two methods for finding unique values in an array of objects: a vanilla JavaScript approach and using the Lodash library's `_.uniqBy` function. **Test Cases:** * **"js"**: This test case uses a filter method with a custom callback function to achieve uniqueness. The callback checks if the current value's `a` property already exists in the array. * **Pros**: Demonstrates fundamental JavaScript concepts like filtering and arrays. Potentially more performant for simple use cases if optimized. * **Cons**: Can be less readable than using specialized libraries, especially for complex operations. * **"lodash"**: This test case utilizes Lodash's `_.uniqBy` function, which directly identifies unique values based on a specified property (in this case, 'a'). Lodash is a popular JavaScript library that provides utility functions for common tasks. * **Pros**: Concise and readable code, leverage the optimized implementation of Lodash. * **Cons**: Adds an external dependency to your project, which can increase bundle size. **Other Considerations:** * **Data Structure**: The benchmark's data is an array of objects with a single property (`a`). Different data structures (e.g., arrays of strings, nested objects) might lead to varying performance results. * **Performance Measurement**: The benchmark reports "ExecutionsPerSecond," indicating how many times the code can run per second. This metric is influenced by factors like hardware, software environment, and JavaScript engine optimizations. **Alternatives:** 1. **Map**: Instead of filtering, you could use a Map to store encountered values efficiently, checking for uniqueness before adding an element. 2. **Set**: If your data consists solely of primitive values (numbers, strings), using a Set directly would provide an O(1) lookup time for checking uniqueness. Let me know if you'd like me to elaborate on any of these points!
Related benchmarks:
uniqBy vs stringify performance
uniqBy performance ttt
lodash uniqBy vs custom uniqBy
uniqBy performance lodash vs native
Comments
Confirm delete:
Do you really want to delete benchmark?