Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Delete vs filter for objects
(version: 0)
Measure the performance of delete versus removing a prop from an object
Comparing performance of:
delete vs filter
Created:
4 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
filter
const res = Object.fromEntries(Object.entries(obj).filter(k => k !== 'a'))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
delete
filter
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/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
delete
110431720.0 Ops/sec
filter
3729394.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Definition** The benchmark is designed to measure the performance of two approaches: `delete` and `filter`. **Options Compared** Two options are compared: 1. **Delete**: This approach uses the `delete` keyword to delete a property from an object. 2. **Filter**: This approach uses the `filter()` method to remove a specific property from an object. **Pros and Cons of Each Approach** * **Delete**: + Pros: Fast, lightweight, and straightforward. + Cons: Does not modify the original object; instead, it returns `undefined`. Also, some older browsers might not support it. * **Filter**: + Pros: Works across most modern browsers, including those with older JavaScript engines. It also modifies the original object by returning a new one with the deleted property removed. + Cons: Can be slower and more memory-intensive than the `delete` approach due to the overhead of creating a new object. **Library and Its Purpose** In this benchmark, no specific library is used beyond the built-in JavaScript functions. However, it's worth noting that some browsers might have additional libraries or modules that can influence the performance of these operations. **Special JS Features or Syntax** None are explicitly mentioned in this benchmark. However, if you're curious about other features like `let` and `const`, they were introduced in ECMAScript 2015 (ES6) and provide scoping and block-level declarations, respectively. **Other Alternatives** Alternative approaches to delete and filter might include: * **Object.assign()**: Replaces an existing property with a new value. * **Object.keys(), Object.values(), Object.entries()**: Create arrays of keys or values, which can be used to iterate over the object's properties. * **Array.prototype.map()**: Creates a new array with filtered elements. Keep in mind that these alternatives might not offer significant performance benefits for this specific use case and could introduce additional overhead due to the complexity of iteration. By running these benchmarks on various browsers and devices, MeasureThat.net provides valuable insights into the performance differences between different approaches to deleting properties from objects.
Related benchmarks:
Delete vs destructure for objects
Delete vs destructure for objects 2
Delete vs destructure for objects v2 2
Delete vs destructure for objects without mutating 2
Comments
Confirm delete:
Do you really want to delete benchmark?