Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Destructure from Object.seal vs Object.freeze vs normal
(version: 0)
Comparing performance of:
seal vs normal vs freeze
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = Object.seal( {x: 321, y: 123} ); var b = {x: 321, y: 123} var c = Object.freeze( {x: 321, y: 123} );
Tests:
seal
const {x,y} = a
normal
const {x,y} = b
freeze
const {x,y} = c
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
seal
normal
freeze
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; rv:133.0) Gecko/20100101 Firefox/133.0
Browser/OS:
Firefox 133 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
seal
835079936.0 Ops/sec
normal
835600384.0 Ops/sec
freeze
837072832.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided benchmark. **Benchmark Definition** The benchmark measures the performance difference between three approaches to prevent property modification on an object: 1. **`Object.seal()`**: This method returns a sealable object, which is similar to `Object.freeze()`, but allows some operations like enumeration. 2. **`Object.freeze()`**: This method freezes an object, making it immutable and preventing any modifications. 3. **Normal (no sealing or freezing)**: In this approach, no special measures are taken to prevent property modification. **Options Compared** The benchmark compares the performance of these three approaches: * `Object.seal()`: Seals the object, allowing some operations like enumeration. * `Object.freeze()`**: Freezes the object, making it immutable and preventing any modifications. * Normal: Does not seal or freeze the object. **Pros and Cons** Here are some pros and cons of each approach: * **`Object.seal()`**: * Pros: * Faster execution compared to `Object.freeze()`. * Allows some operations like enumeration. * Cons: * Does not make the object completely immutable. * Can be vulnerable to certain attacks, such as using `Object.prototype.hasOwnProperty.call()` to check if a property exists on the sealable object. * **`Object.freeze()`**: * Pros: * Makes the object completely immutable. * Provides strong security guarantees. * Cons: * Slower execution compared to `Object.seal()`. * Normal (no sealing or freezing): * Pros: * No additional overhead or impact on performance. * Cons: * Does not provide any protection against property modification. **Library and Special JS Features** There are no specific libraries used in this benchmark. However, the `Object.prototype.hasOwnProperty.call()` function is used to check if a property exists on the sealable object. No special JavaScript features (like async/await or destructuring) are used in this benchmark. **Other Alternatives** Some alternative approaches to prevent property modification include: * Using `const` and `let` keywords instead of `var`. * Using `Object.defineProperty()` with `configurable: false`, `writable: false`, and `enumerable: false`. * Using a library like Lodash's `pick()` function. * Implementing custom getters and setters for specific properties. In conclusion, the benchmark provides an insightful comparison of three approaches to prevent property modification on objects. By understanding the pros and cons of each approach, developers can make informed decisions about which method best suits their use case and performance requirements.
Related benchmarks:
Destructure from Object.seal vs Object.freeze vs normal(special edition)
Object.freeze vs Object.seal vs Native
Access from Object.seal vs Object.freeze vs normal
normal vs Object.freeze vs Object.seal performance
Comments
Confirm delete:
Do you really want to delete benchmark?