Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
delete vs use spread to omit property
(version: 1)
Comparing performance of:
delete vs spread vs set undefined
Created:
4 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var obj = { a:1, b:2, c:3 }
Tests:
delete
delete obj.a
spread
obj = {...obj, a: undefined}
set undefined
obj.a = undefined
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
delete
spread
set undefined
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Browser/OS:
Chrome 119 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
delete
15580771.0 Ops/sec
spread
3877919.5 Ops/sec
set undefined
6024737.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in the provided benchmark. **Benchmark Definition** The benchmark is designed to compare three different approaches to "omitting" a property from an object: 1. `delete obj.a` 2. Using the spread operator (`obj = {...obj, a: undefined}`) to create a new object with the desired properties removed. 3. Setting the property to `undefined` directly (`obj.a = undefined`) **Options being compared** The three options are being compared in terms of performance, specifically the number of executions per second. **Pros and Cons of each approach** 1. `delete obj.a`: * Pros: Simple and concise. * Cons: Can be slower due to the dynamic nature of object property access. 2. Using the spread operator (`obj = {...obj, a: undefined}`): * Pros: More explicit and readable, as it creates a new object with the desired properties removed. * Cons: Can be slower due to the creation of a new object and the use of the spread operator. 3. Setting the property to `undefined` directly (`obj.a = undefined`): * Pros: Fast and efficient, as it simply sets the property value. * Cons: May not be as explicit or readable as the other two approaches. **Library usage** None of the provided benchmark definitions use any external libraries. **Special JS feature/syntax** The spread operator (`{...obj, a: undefined}`) is used in one of the test cases. This syntax is a modern JavaScript feature introduced in ECMAScript 2018 (ES9). **Other considerations** * The `DevicePlatform` and `OperatingSystem` fields suggest that the benchmark is run on a desktop environment. * The `ExecutionsPerSecond` field indicates the number of executions performed per second, which can be an indicator of performance. **Alternatives** If you wanted to create a similar benchmark, you could consider adding additional test cases, such as: * Using the `delete` operator in combination with other operators (e.g., `delete obj.a && delete obj.b`) * Comparing the performance of each approach on different types of objects (e.g., arrays, sets, etc.) * Adding test cases for other ways to omit properties from an object (e.g., using a function or a library like Lodash)
Related benchmarks:
Delete vs destructure for objects
Object property: delete vs undefined 2
Delete vs destructure for objects 2
Delete vs destructure for objects v2 2
Comments
Confirm delete:
Do you really want to delete benchmark?