var obj = {
a: { b: 1 },
c: 'd',
e: false
}
var obj2 = { obj };
delete obj2.c
const { c, obj2 } = obj;
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
delete | |
rest |
Test name | Executions per second |
---|---|
delete | 2872778.2 Ops/sec |
rest | 2420622.2 Ops/sec |
Let's break down the provided benchmark and explain what's being tested.
Benchmark Definition
The benchmark is titled "Delete vs destructure for cloned objects". It's asking to measure the performance of two different approaches:
delete
keyword.Options Compared
The benchmark is comparing the performance of these two approaches on an object with three properties: a
, c
, and e
.
Pros and Cons of Each Approach
Library Used
In this benchmark, the ...
operator is used to implement destructuring. The ...
operator is a spread operator that extracts properties from an object into new variables. It's part of the ECMAScript 2015 (ES6) standard and is widely supported in modern browsers.
Special JS Feature/Syntax
The benchmark uses the const
keyword, which was introduced in ES6 as well. const
is used to declare variables that cannot be reassigned.
Other Considerations
Alternatives
Some alternative approaches to consider:
delete
keyword, you could use obj.propertyName = undefined;
. While this works, it may not be as efficient as destructuring.To run a new benchmark on MeasureThat.net, users would create a new test case with their own script preparation code and HTML preparation code (if needed), and then execute the benchmark to generate results.