Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Delete vs destructure for objects v2 2
(version: 0)
Measure the performance of delete versus removing a prop from an object
Comparing performance of:
delete vs Rest object
Created:
3 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:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
delete
79213232.0 Ops/sec
Rest object
2906867.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its components. **Benchmark Definition** The benchmark is defined by a JSON object that contains information about the test case: * `Name`: The name of the benchmark, which in this case is "Delete vs destructure for objects v2 2". * `Description`: A brief description of what the benchmark measures. * `Script Preparation Code` and `Html Preparation Code`: These are codes that are executed before running the benchmark. In this case, only the script preparation code is provided. **Script Preparation Code** The script preparation code is a JavaScript snippet that creates an object with three properties: `a`, `b`, and `c`. The object is assigned to a variable named `obj`. ```javascript var obj = { a:1, b:2, c:3 }; ``` **Individual Test Cases** The benchmark consists of two individual test cases: * **delete**: This test case measures the performance of using the `delete` keyword to remove a property from an object. The benchmark definition is: `delete obj.a`. * **Rest object**: This test case measures the performance of creating a rest object using destructuring assignment. The benchmark definition is: `const { a, ...rest } = obj;`. **Options Compared** The two test cases compare different approaches to removing properties from an object. 1. **Delete**: Using the `delete` keyword. 2. **Destructure**: Creating a rest object using destructuring assignment (`{ a, ...rest } = obj`). **Pros and Cons of Each Approach** * **Delete**: + Pros: Simple and straightforward syntax. + Cons: Can be slower due to the overhead of removing a property from an object. * **Destructure**: + Pros: More concise syntax and potentially faster performance since it avoids modifying the original object. + Cons: Requires JavaScript 2015+ syntax, which not all browsers support. **Library Used (if any)** None. **Special JS Feature or Syntax** The `Rest object` test case uses a feature introduced in ECMAScript 2015 (ES6) called destructuring assignment. This feature allows you to create new objects by extracting properties from an existing object. ```javascript const { a, ...rest } = obj; ``` In this example, the expression `{ a, ...rest } = obj` creates a new object `rest` that includes all properties of `obj`, except for `a`. **Other Alternatives** While not exactly equivalent, other ways to remove properties from an object could be: * Using `Object.prototype.hasOwnProperty.call(obj, 'a') && delete obj['a']` * Creating a new object with the desired properties and then assigning it to a variable * Using `Array.prototype.slice.call(Object.keys(obj).map(key => ({ [key]: obj[key] }))` However, these alternatives are not as concise or efficient as using the `delete` keyword or destructuring assignment.
Related benchmarks:
Delete vs destructure for objects
Delete vs destructure for cloned objects
Delete vs destructure for objects 2
Delete vs destructure for objects without mutating 2
Comments
Confirm delete:
Do you really want to delete benchmark?