Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
New set vs set clear
(version: 0)
Comparing performance of:
new set vs clear set
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const permSet = new Set() for (let i = 0; i < 100; i++) { permSet.add(Math.floor(Math.random() * 100000)); }
Tests:
new set
permSet = new Set()
clear set
permSet.clear()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
new set
clear set
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
new set
0.0 Ops/sec
clear set
105082456.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided JSON and explain what's being tested, compared, and some of the considerations involved. **Benchmark Definition** The benchmark definition is testing two approaches: creating a new Set object (`"permSet = new Set()"`) versus clearing an existing Set object (`"permSet.clear()"`). A Set in JavaScript is a collection of unique values. It's similar to an array, but it doesn't allow duplicate values. **Options Compared** The two options being compared are: 1. **Creating a new Set object**: This approach creates a fresh Set instance and populates it with 100 random integers. 2. **Clearing an existing Set object**: This approach clears the existing `permSet` object (which is already populated) and does nothing else. **Pros and Cons of Each Approach** 1. **Creating a new Set object**: * Pros: Creates a fresh, empty Set instance from scratch, which can be faster for certain use cases. * Cons: Requires more memory allocation and potentially slower due to the overhead of creating a new object. 2. **Clearing an existing Set object**: * Pros: Reuses an already created and populated Set instance, reducing memory allocation and potential overhead. * Cons: Can be slower if the set needs to be rebuilt or reserialized, as it involves clearing the existing data. **Other Considerations** * Memory allocation and deallocation can impact performance, especially for large datasets. * The `clear()` method is generally faster than creating a new object from scratch because it only requires updating the internal data structure of the Set instance. **Library and Purpose** In this benchmark, no specific library is used. However, if you were to create a real-world application using JavaScript, libraries like Lodash or Ramda might be useful for working with Sets, but they are not relevant to this specific benchmark. **Special JS Feature or Syntax** There's no special JS feature or syntax being tested in this benchmark. The focus is on the performance comparison between creating a new Set object and clearing an existing one. **Alternatives** If you were to write your own JavaScript microbenchmark, here are some alternatives: * Create a simple array-based benchmark: Replace Sets with arrays and test how quickly they can be populated or cleared. * Use a library like WebPerf or Microbench to create and run benchmarks. * Implement the benchmark yourself using a framework like Jest or Mocha. Keep in mind that these alternatives might not provide the same level of nuance and detail as MeasureThat.net, but they can still help you understand performance characteristics in JavaScript.
Related benchmarks:
Fill array with random integers
for...of Set vs. array conversion
.at vs [x]
global let vs local const_mohammadBaghaei
Object vs Map lookup: random integer key
Comments
Confirm delete:
Do you really want to delete benchmark?