Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Delete vs destructure for objects in loop
(version: 0)
Measure the performance of delete versus removing a prop from an object in loop
Comparing performance of:
delete vs Rest object
Created:
4 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var obj = {} for (let i = 0; i < 1000; i++) { obj[`test_${i}`] = `value_${i}`; }
Tests:
delete
const newObject = { ...obj }; Object.keys(newObject).forEach(key => { delete newObject[key]; });
Rest object
let newObject = obj; Object.keys(newObject).forEach(property => { let {[property]:ignored, ...rest} = newObject newObject = rest; });
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 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
delete
3492.3 Ops/sec
Rest object
15.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested, compared, and some considerations. **Benchmark Purpose** The primary goal of this benchmark is to measure the performance difference between two approaches: 1. Deleting properties from an object using `delete`. 2. Removing properties from an object by destructuring it into a new object with only the desired properties (`...rest`). **Options Compared** Two options are being compared: * **Delete**: Using the `delete` operator to remove properties from the object. * **Rest object**: Destructuring the object and creating a new one with only the desired properties. **Pros and Cons of Each Approach:** 1. **Delete**: * Pros: + Easy to understand and implement. + Works for any property, regardless of its name or value. * Cons: + Can be slower due to the overhead of calling `delete` on each property. + May cause issues with property names that are reserved keywords in JavaScript (e.g., `break`, `case`, etc.). 2. **Rest object**: * Pros: + Typically faster than using `delete`. + Avoids potential issues with reserved keywords. * Cons: + Requires a good understanding of destructuring syntax and can be more error-prone if not implemented correctly. **Library or Special JS Feature Used:** Neither option uses any external libraries, but they do rely on JavaScript's built-in features: 1. **Delete**: The `delete` operator is a native JavaScript function. 2. **Rest object**: Destructuring syntax (`...rest`) is a feature introduced in ECMAScript 2015 (ES6). **Other Considerations:** * The benchmark uses a simple object creation and property assignment pattern to warm up the interpreter before running each test. * Both tests have similar execution patterns, with the `delete` option deleting all properties from the object, while the `Rest object` option only removes the desired properties. **Alternatives:** Other approaches to removing properties from an object could include: 1. Using a library like Lodash's `omit()` function. 2. Creating a new object with only the desired properties using the spread operator (`{ ...newObject }`). 3. Using a different data structure, such as an array or a Map, if possible. However, these alternatives may not be relevant to this specific benchmark, which focuses on comparing the performance of `delete` versus destructuring syntax.
Related benchmarks:
Delete vs destructure for 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?