Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Testing speed with Reflect.deleteProperty and delete
(version: 0)
Comparing performance of:
Reflect.deleteProperty vs object delete
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var numbers = Array(10).fill(null).map((x, i) => ({[i]: `${i}- ${i}`, [i+1]: i+1 }));
Tests:
Reflect.deleteProperty
numbers.forEach((number, index)=> Reflect.deleteProperty(number, index))
object delete
numbers.forEach((number, index)=> delete number[index])
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Reflect.deleteProperty
object delete
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/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Reflect.deleteProperty
4654816.5 Ops/sec
object delete
5508000.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain the benchmark and its different approaches. **Benchmark Overview** The test measures the performance of two JavaScript methods: `Reflect.deleteProperty` and the built-in `delete` operator, both used to delete properties from an object. **Script Preparation Code** The script preparation code creates a large array `numbers` with 10 elements, each containing two properties: `[i]: `${i}- ${i}`, [i+1]: i+1`. This creates a dense object with many key-value pairs. **Test Cases** There are two test cases: 1. **Reflect.deleteProperty**: This test case uses the `Reflect.deleteProperty` method to delete the first property of each object in the array. The benchmark definition is: `numbers.forEach((number, index)=> Reflect.deleteProperty(number, index))`. 2. **object delete**: This test case uses the built-in `delete` operator to delete the first property of each object in the array. The benchmark definition is: `numbers.forEach((number, index)=> delete number[index])`. **Options Compared** The two approaches differ in their performance: * **Reflect.deleteProperty**: This method is more efficient than the `delete` operator because it uses a native JavaScript API that's optimized for speed. It also avoids the overhead of property lookup and comparison. * **object delete**: The `delete` operator, on the other hand, requires the engine to perform additional steps: looking up the property, comparing its value with the current value, and updating the object's internal hash table. **Pros and Cons** Here are some pros and cons of each approach: * **Reflect.deleteProperty**: + Pros: - Faster execution speed - More efficient than `delete` operator - Avoids property lookup and comparison overhead + Cons: None notable * **object delete**: + Pros: - Widespread support across browsers and engines - Familiar API for many developers + Cons: - Slower execution speed compared to `Reflect.deleteProperty` - More overhead due to property lookup and comparison **Library or Framework** There is no specific library used in this benchmark. The `Reflect` object is a built-in JavaScript API. **Special JS Feature or Syntax** The test uses the `forEach` method, which is a standard JavaScript feature introduced in ECMAScript 5 (ES5). It's a widely supported and familiar API for many developers. **Other Alternatives** If you're looking for alternatives to `Reflect.deleteProperty`, you could consider: * Using a library like Lodash or Underscore.js, which provide similar functionality. * Implementing your own property deletion logic using a simple loop or recursion. * Exploring other native JavaScript APIs, such as `Object.keys()` and `Object.prototype.hasOwnProperty.call()`, although these may be less efficient than `Reflect.deleteProperty`. Keep in mind that the best approach will depend on your specific use case and performance requirements.
Related benchmarks:
Ryan Test Benchmark
remove by splice vs filter array v4
remove by splice vs filter array v5
Remove by slice vs copyWithin vs filter
Remove by splice vs spread
Comments
Confirm delete:
Do you really want to delete benchmark?