Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
loadAsh UniqBy vs native new set array
(version: 0)
Comparing performance of:
native JS vs uniqBy lodash
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Script Preparation code:
var testObj = []; let numberObj = 99999; for (let i = 0; i < numberObj; i++) { const obj = { hardwareVersion: `samr${Math.floor(Math.random() * 10)}-Valve${Math.floor( Math.random() * 3 )}`, macAdress: "XX:XX:XX:XX:XX:XX".replace(/X/g, function() { return "0123456789ABCDEF".charAt(Math.floor(Math.random() * 3)); }), }; testObj[i] = obj; }
Tests:
native JS
[...new Set(testObj.map((e) => e.macAdress))]
uniqBy lodash
_.uniqBy(testObj, "macAdress")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
native JS
uniqBy lodash
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
native JS
186.3 Ops/sec
uniqBy lodash
111.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested, compared, and their pros/cons. **Benchmark Definition** The benchmark is designed to compare two approaches for creating an array of unique objects based on a specific property, in this case, "macAdress". There are two individual test cases: 1. **Native JS**: This approach uses the `Set` data structure to create an array of unique values. Specifically, it maps over the `testObj` array and converts each object's "macAdress" property to a string using the `replace()` method. 2. **uniqBy lodash**: This approach uses the `_uniqBy()` function from the Lodash library to achieve the same result. The `uniqBy()` function takes an array, a property key (in this case, `"macAdress"`), and returns an array of unique values based on that property. **Comparison** The benchmark compares the performance of these two approaches in terms of executions per second. **Pros/Cons** * **Native JS**: + Pros: Native JavaScript implementation is likely to be more efficient and optimized for the specific use case. + Cons: Requires manual handling of string conversion, which can introduce additional overhead. * **uniqBy lodash**: + Pros: Utilizes a well-tested and widely used library function, reducing development time and potential errors. + Cons: Introduces an external dependency (Lodash) and may incur additional overhead due to the library's functionality. **Library** The `_.uniqBy()` function from Lodash is used in this benchmark. Lodash is a popular utility library for JavaScript that provides various helper functions for tasks such as array manipulation, string manipulation, and more. **Special JS Features/Syntax** There are no special JavaScript features or syntaxes being used in this benchmark. The code uses standard JavaScript features like `Set`, `map()`, and `replace()`. **Other Alternatives** If you wanted to implement a similar benchmark without using Lodash, you could use other libraries or frameworks that provide array manipulation functionality, such as: * Underscore.js * Moment.js (for date manipulation) * Ramda (a functional programming library) Alternatively, you could implement the logic manually using only standard JavaScript features. Keep in mind that when choosing an alternative approach, consider factors like performance, maintainability, and scalability.
Related benchmarks:
lodash uniq vs VanillaJS
Lodash Uniq vs Javascript Set vs Ramda Strings
lodash uniq vs Array.from(new Set()) vs spread new Set() vs for vs for memory optimized 4
lodash uniq vs set my 2
New set vs UniqWith
Comments
Confirm delete:
Do you really want to delete benchmark?