Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Delete vs destructure for objects
(version: 0)
Measure the performance of delete versus removing a prop from an object
Comparing performance of:
delete vs Rest object
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var obj = { a:1, b:2, c:3 }
Tests:
delete
delete obj.a
Rest object
const { a, ...rest } = obj;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
delete
Rest object
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/140.1 Mobile/15E148 Safari/605.1.15
Browser/OS:
Mobile Safari 18 on iOS 18.5
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
delete
490682784.0 Ops/sec
Rest object
22217432.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark is designed to measure the performance of two different approaches: 1. **Delete**: This approach uses the `delete` operator to remove a property from an object. 2. **Rest Object**: This approach uses destructuring assignment ( introduced in ECMAScript 2015) to extract a subset of properties from an object. **Options being compared** The benchmark compares two options for removing or extracting properties from an object: 1. `delete` operator 2. Destructuring assignment ( `const { a, ...rest } = obj;` ) **Pros and Cons** ### Delete Operator Pros: * Simple and straightforward syntax * Widely supported in most browsers and JavaScript engines * Can be used with any type of object, not just objects Cons: * May involve more overhead due to the creation of a new variable ( `obj.a` ) * Can lead to unexpected behavior if not used carefully (e.g., modifying the original object) ### Destructuring Assignment Pros: * More concise and expressive syntax * Only creates a copy of the subset of properties, which can be beneficial for large objects * Less likely to modify the original object unintentionally Cons: * Introduced in ECMAScript 2015, so may not be supported in older browsers or engines * Requires knowledge of destructuring assignment syntax **Library and Special JS Feature** There is no explicit library mentioned in the benchmark definition. However, it's worth noting that the use of `const { a, ...rest } = obj;` demonstrates the use of destructuring assignment, which is a standard JavaScript feature. **Other Alternatives** If you're interested in exploring other alternatives for removing or extracting properties from an object, here are a few options: * Using a function to dynamically remove properties (e.g., `function removeProperty(obj, key) { delete obj[key]; }`) * Using a library like Lodash's `remove` function * Using a custom implementation of object removal, such as using a hash table to store property names and values Keep in mind that these alternatives may have different performance characteristics or trade-offs compared to the `delete` operator and destructuring assignment.
Related benchmarks:
Delete vs destructure for cloned objects
Delete vs destructure for objects v2 2
Delete vs destructure for objects without mutating pedro
Delete vs destructure for objects without mutating 2
Comments
Confirm delete:
Do you really want to delete benchmark?