Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set union
(version: 0)
Comparing performance of:
spread vs Generator
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var set1 = new Set(`hNF3l0P4cN QQfOLyCS4x ZszvkTI37o IynKxZthCK ouwci5cS7j r7jX5XQb1p 1dj2hYGU60 4Q6utWsqC6 XmTmsXafwn EvvglORogV G2sWUp3k9g oso9pMt1NB mSJpyz5XdL AiZWvwpGqD mH6YqIcvTt 5k6d0LaiGh ZI511srBaE nU6OeCjDP3 REi51NlQF1 G3wOYKZ4kb`.split(/\s/g)); var set2 = new Set(`IIVSIoKcV7 scRjrTjTwX peydSQMOfd Sp3F2lZ2Ae rPb1Omg5yB STpbhl8ICX MlAd0k8ivJ AffgUA9jhc FjNg0f21G7 EkJqj5b6kI nKMvAL4n6F 5KsVjUQtw1 MBpocHEPvW M246F2AaCW YXFNxRHBEZ MWOvSvDomc Mdhe89kU1N arVnYE1hfy BIPP10nDR2 mxAFx10DH4`.split(/\s/g));
Tests:
spread
var result = new Set([...set1, ...set2]);
Generator
var result = new Set(function*(){ yield* set1; yield* set2; }());
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
spread
Generator
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
spread
875539.1 Ops/sec
Generator
117693.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what is being tested on MeasureThat.net. **Benchmark Definition** The benchmark definition represents a JavaScript function that creates a set by concatenating two sets using the spread operator (`...`). The code: ```javascript var result = new Set([...set1, ...set2]); ``` is compared across different approaches. **Approaches Compared** There are two approaches being compared: 1. **Spread Operator**: Using the spread operator (`...`) to concatenate the sets. 2. **Generator**: Using a generator function to yield each set element individually. **Pros and Cons of Each Approach** **Spread Operator:** Pros: * Fast and efficient, as it uses a optimized internal implementation. * Easy to read and understand for developers familiar with JavaScript. Cons: * May not be compatible with older browsers or environments that don't support the spread operator. **Generator:** Pros: * Can be useful in certain scenarios where using a generator function provides additional benefits (e.g., iteration, chaining). * Can help optimize performance by avoiding unnecessary set creation. Cons: * Less intuitive and more verbose compared to the spread operator. * May incur additional overhead due to the use of a generator function. **Library Used** The `Set` class is used in both approaches. A `Set` is a collection of unique values, which is essential for this benchmark. **Special JS Feature or Syntax** There are no special JavaScript features or syntax used in this benchmark that would require specific knowledge to understand. **Other Alternatives** If the spread operator were not available, an alternative approach could be using the `concat()` method: ```javascript var result = new Set(set1.concat(set2)); ``` However, this approach is generally slower and less efficient than the spread operator. Another alternative would be using a library like Lodash's `unionBy` function: ```javascript var _ = require('lodash'); var result = _.unionBy(set1, set2); ``` But again, this approach may incur additional overhead due to the use of a third-party library. **Benchmark Preparation Code** The script preparation code is used to create two sets (`set1` and `set2`) containing large numbers of strings. These sets are then used in the benchmark to test the performance of each approach. I hope this explanation helps software engineers understand what's being tested on MeasureThat.net!
Related benchmarks:
Split string
addzone_split
addzone_split_1
String COMPARE
Comments
Confirm delete:
Do you really want to delete benchmark?