Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Delete performance
(version: 0)
Comparing performance of:
removeNullish vs delete vs Create Array
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
removeNullish
const arr = new Array(500000).fill(null).map(() => ({ "item": 42 })) const removeNullish = (obj) => Object.entries(obj).reduce((a, [k, v]) => (v ? ((a[k] = v), a) : a), {}) arr.forEach(object => { object.item = undefined removeNullish(object) })
delete
const arr = new Array(500000).fill(null).map(() => ({ "item": 42 })) arr.forEach(object => { delete object.item })
Create Array
const arr = new Array(500000).fill(null).map(() => ({ "item": 42 })) const removeNullish = (obj) => Object.entries(obj).reduce((a, [k, v]) => (v ? ((a[k] = v), a) : a), {})
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
removeNullish
delete
Create Array
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
removeNullish
20.9 Ops/sec
delete
27.3 Ops/sec
Create Array
75.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Measuring the performance of JavaScript operations is crucial for optimizing web applications and identifying areas where improvements can be made. **Overview of Benchmark** The provided benchmark measures the performance of three different approaches: 1. **Delete**: This approach uses the built-in `delete` keyword to remove the `item` property from each object in the array. 2. **RemoveNullish**: This approach uses a custom function (`removeNullish`) to iterate over the objects in the array and only assign values if they are not nullish (i.e., either truthy or an empty string). 3. **Create Array**: This approach creates an array of 500,000 objects with a single property `item` initialized to 42. **Options Compared** The benchmark compares the performance of these three approaches: * **Delete**: Directly deletes the `item` property using the built-in `delete` keyword. * **RemoveNullish**: Uses a custom function to iterate over the objects and only assign values if they are not nullish. * **Create Array**: Creates an array with 500,000 objects and assigns a value to each object's `item` property. **Pros and Cons of Each Approach** 1. **Delete**: * Pros: Simple, straightforward, and likely to be the most efficient approach since it uses built-in functionality. * Cons: May not handle cases where the property is not present in the object (returns undefined instead). 2. **RemoveNullish**: * Pros: Handles nullish values by only assigning values if they are truthy or an empty string. * Cons: Uses a custom function, which may incur overhead due to function call and binding costs. 3. **Create Array**: * Pros: Allows for easy comparison of object creation performance without affecting the benchmark's result. * Cons: Creates a new array with 500,000 objects, which can lead to performance issues. **Library Used** None explicitly mentioned in the provided benchmark definition. **Special JS Features or Syntax** The `removeNullish` function uses a feature called "rest properties" (e.g., `[k, v]`) and arrow functions (`() => ...`). These features are not specific to this benchmark but are part of modern JavaScript syntax. They provide concise ways to express code, making it easier to read and maintain. **Other Alternatives** If you're looking for alternatives or have questions about these approaches: * **Using `delete` with `in` operator**: Instead of using the built-in `delete` keyword, you can use the `in` operator to check if a property exists before deleting it. This approach might be slower due to the overhead of the `in` operator. Example: ```javascript arr.forEach(object => { if ('item' in object) { delete object['item']; } }); ``` * **Using `forEach` with a callback function**: Instead of using `arr.forEach`, you can use an arrow function with a callback to achieve the same result. This approach might be slower due to the overhead of creating and executing a new function. Example: ```javascript arr.forEach(object => { object.item = undefined; }); ``` Keep in mind that these alternatives may not provide significant performance benefits unless you're dealing with extremely large datasets or performance-critical code. I hope this explanation helps!
Related benchmarks:
Remove by splice vs copyWithin vs filter vs set.delete
Delete or not delete
Remove by splice vs filter
Map() delete while iterating vs clear
Omit in loop vs Delete vs pure delete
Comments
Confirm delete:
Do you really want to delete benchmark?