Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash _.union vs native Set() with large arrays using spread
(version: 0)
Comparing performance of:
_.union vs Set() spread into array
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js"></script>
Script Preparation code:
var a = new Array(1000).map((x,i) => i); var b = new Array(500).map((x,i) => 500 - i)
Tests:
_.union
var c = _.union(a, b)
Set() spread into array
var c = [...(new Set([...a, ...b]))]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.union
Set() spread into array
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/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.union
61252.8 Ops/sec
Set() spread into array
71630.1 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 in the benchmark. **Benchmark Definition** The website uses a JSON object to define the benchmark, which includes: * `Name`: A unique name for the benchmark, "Lodash _.union vs native Set() with large arrays using spread". * `Description`: An empty string, indicating that no description is provided. * `Script Preparation Code` and `Html Preparation Code`: These two sections specify the code that needs to be executed before running the benchmark. The script prepares two large arrays, `a` and `b`, using array destructuring and map functions. The HTML preparation code includes a link to load the Lodash library. **Individual Test Cases** The benchmark consists of two individual test cases: 1. **Test Case 1: `_` union** * **Benchmark Definition**: `var c = _.union(a, b)`. * **Purpose**: This test case measures the performance of the `_.union()` function from Lodash when used to merge two large arrays. 2. **Test Case 2: Native Set() with spread** * **Benchmark Definition**: `var c = [...(new Set([...a, ...b]))]`. * **Purpose**: This test case measures the performance of merging two large arrays using the native `Set()` function and array spread operator. **Comparison of Approaches** The benchmark compares the performance of two approaches: 1. **Lodash _.union()**: The first approach uses the `_` union function from Lodash to merge the two arrays. 2. **Native Set() with array spread**: The second approach uses the native `Set()` function and array spread operator (`...`) to merge the two arrays. **Pros and Cons of Each Approach** Here are some pros and cons for each approach: * **Lodash _.union()**: * Pros: * Easier to read and maintain, as it's a well-documented and tested function. * May be faster due to potential optimizations within the Lodash library. * Cons: * May introduce unnecessary overhead due to the additional function call and argument passing. * **Native Set() with array spread**: * Pros: * Lightweight, as it only uses built-in JavaScript functions. * Can be faster in some cases due to optimized native code. * Cons: * May have a steeper learning curve due to the use of new syntax and features. **Library: Lodash** Lodash is a popular JavaScript utility library that provides various functions for tasks such as array manipulation, object transformation, and more. The `_` union function in this benchmark is used to merge two arrays, eliminating duplicates while preserving order. The test case uses the latest version of Lodash (4.17.10) available on CDN. **Special JS Feature/Syntax** This benchmark does not use any special JavaScript features or syntax that would require additional explanation. However, it's worth noting that the array spread operator (`...`) and native `Set()` function are relatively new features introduced in ECMAScript 2015 (ES6) and later versions. **Alternatives** If you're looking for alternatives to benchmarking JavaScript performance, consider: 1. **V8 Benchmark Suite**: A comprehensive set of benchmarks developed by Google's V8 engine team. 2. **JSPerf**: A popular benchmarking tool that allows running multiple tests in a single execution. 3. **BenchmarkDotNet**: An open-source benchmarking library for .NET languages, including JavaScript. These tools can help you compare performance across different browsers, environments, and approaches, ensuring optimal execution times for your applications.
Related benchmarks:
Lodash union vs Native Javascript
Corrected Lodash _.union vs native Set()
Lodash _.union vs native Set() with large arrays
lodash union vs native set spread
Comments
Confirm delete:
Do you really want to delete benchmark?