var set = new Set();
var object = {};
var array = new Array(5000).fill().map((_, i) => i);
for (let i = 0; i < array.length; i++) {
object[i] = true;
}
for (let i = 0; i < array.length; i++) {
set.add(i);
}
delete object[40]
set.delete(40)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Object | |
Set |
Test name | Executions per second |
---|---|
Object | 48074272.0 Ops/sec |
Set | 36277352.0 Ops/sec |
Let's break down the provided benchmark and explain what's being tested, compared options, pros and cons of each approach, and other considerations.
Benchmark Overview
The benchmark measures the performance difference between deleting an element from an object versus deleting it from a Set data structure. The test creates an array of 5000 elements and populates an object with a boolean value for each index. Then, it adds all indices to a Set and deletes one specific index (40) using both methods.
Options Compared
There are two options being compared:
Pros and Cons of Each Approach
delete
on objects).Other Considerations
The benchmark also considers the following:
Additional Insights
The use of fill()
and map()
functions in the script preparation code allows for a more efficient creation of the array and object, as well as populating the object with boolean values. The Set data structure is created using the Set
constructor, which is optimized for fast lookups and removals.
In terms of special JS features or syntax, there are no notable mentions in the provided benchmark code or JSON definitions.