Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs spread new Set() medium size
(version: 0)
This checks for medium sized duplicated input to contain unique entries
Comparing performance of:
Spread vs use lodash
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js'></script>
Script Preparation code:
var input = Array.from({ length: 500 }, (_, i) => i - (i % 2 == 0 ? 0 : 1))
Tests:
Spread
return [...new Set(input)]
use lodash
return _.uniq(input);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Spread
use lodash
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36 Edg/136.0.0.0
Browser/OS:
Chrome 136 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Spread
174834.7 Ops/sec
use lodash
133454.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Overview** The benchmark compares two approaches to remove duplicate entries from an array of numbers: 1. **Spread approach**: Using the spread operator (`...`) to convert the array into a new set, which automatically removes duplicates. 2. **Lodash uniq approach**: Using the `uniq` function from the Lodash library to remove duplicates. **Options Compared** The benchmark is comparing two options: * **Spread approach (using JavaScript's built-in `Set` object)**: This method uses the spread operator to convert the array into a new set, which automatically removes duplicates. The `Set` object in JavaScript is designed to store unique values. * **Lodash uniq approach**: This method uses the `uniq` function from Lodash to remove duplicates. **Pros and Cons** **Spread Approach:** Pros: * Fast and efficient, as it leverages the optimized implementation of the `Set` object in JavaScript. * Does not require any additional libraries or dependencies. Cons: * May not be as readable or concise for developers who are not familiar with the spread operator or `Set`. * Can be slower than the Lodash approach if the input array is very large, due to the overhead of creating a new set. **Lodash Uniq Approach:** Pros: * More readable and concise, especially for developers who are familiar with Lodash. * May perform better for very large inputs, as it avoids the overhead of creating a new set. Cons: * Requires an additional library (Lodash) to be included in the test environment. * Can be slower than the spread approach due to the overhead of calling a function from a library. **Other Considerations** The benchmark is testing the performance difference between these two approaches on medium-sized input data. The input data is generated using an array of numbers with 500 elements, where every other element is a duplicate. **Library Used (Lodash)** Lodash is a popular JavaScript utility library that provides a set of reusable functions for common tasks, such as array manipulation, string manipulation, and more. In this benchmark, Lodash is used to provide the `uniq` function, which removes duplicates from an array. **Special JS Feature/Syntax** There are no special JavaScript features or syntax mentioned in the benchmark definition. Both approaches use standard JavaScript syntax and built-in objects (e.g., arrays, sets). **Alternatives** If you're interested in exploring other alternatives, here are a few options: * Using the `filter` method to remove duplicates: This approach involves filtering out elements that already exist in the array. * Using a custom implementation of a set data structure: This approach would involve implementing a custom data structure that can efficiently store and retrieve unique values. Keep in mind that these alternatives may not be as efficient or readable as the spread approach or Lodash uniq approach, depending on the specific use case.
Related benchmarks:
lodash uniq vs native uniq
lodash uniq vs Array.from(new Set()) vs spread new Set() vs array.filter
Lodash uniq vs Set to unique array
lodash uniq vs spread new Set()
Comments
Confirm delete:
Do you really want to delete benchmark?