const map1 = new Map()
map1.set('a', 999);
map1.set('b', 3000);
const a = {
}
a.a= 999;
a.b= 3000;
a.a = null;
a.b = null;
const map1 = new Map()
map1.set('a', 999);
map1.set('b', 3000);
const a = {
}
a.a= 999;
a.b= 3000;
a.a = undefined;
a.b = undefined;
const map1 = new Map()
map1.set('a', 999);
map1.set('b', 3000);
const a = {
}
a.a= 999;
a.b= 3000;
delete a.a;
delete a.b;
const map1 = new Map()
map1.set('a', 999);
map1.set('b', 3000);
const a = {
}
a.a= 999;
a.b= 3000;
map1.set('a', null);
map1.set('b', null);
const map1 = new Map()
map1.set('a', 999);
map1.set('b', 3000);
const a = {
}
a.a= 999;
a.b= 3000;
map1.set('a', undefined);
map1.set('b', undefined);
const map1 = new Map()
map1.set('a', 999);
map1.set('b', 3000);
const a = {
}
a.a= 999;
a.b= 3000;
map1.delete('a');
map1.delete('b');
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
null Object | |
undefined Object | |
delete object | |
null map | |
undefined map | |
delete map |
Test name | Executions per second |
---|---|
null Object | 35984104.0 Ops/sec |
undefined Object | 34681016.0 Ops/sec |
delete object | 10126811.0 Ops/sec |
null map | 26443220.0 Ops/sec |
undefined map | 26570784.0 Ops/sec |
delete map | 18094938.0 Ops/sec |
Let's break down the provided benchmark and analyze what's being tested, compared, and their pros and cons.
What is being tested:
The benchmark compares the performance of different approaches to delete or nullify JavaScript objects (and maps). The four main approaches are:
delete a.a
and delete a.b
)a.a = null
and a.b = null
)map1.set('a', null)
and map1.set('b', null)
)a.a = undefined
and a.b = undefined
)delete a
and delete map1
)Options compared:
The benchmark compares the performance of each approach in terms of the number of executions per second.
Pros and Cons of each approach:
Library and purpose:
The Map
data structure is used in this benchmark, which is a built-in JavaScript object that stores key-value pairs. It provides fast lookup, insertion, and deletion operations.
Other considerations:
delete
operator.Alternatives:
Other alternatives to measure object deletion performance include:
assign
, unset
methodsKeep in mind that the choice of benchmark depends on the specific use case and requirements. This analysis provides a general understanding of the approaches being tested and their pros and cons.