Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.freeze vs Object.seal (only property access)
(version: 0)
Comparing performance of:
normal vs freeze vs seal
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var normal = { x: 0, y: 0 }; var freeze = Object.freeze({ x: 0, y: 0 }); var seal = Object.seal({ x: 0, y: 0 });
Tests:
normal
if (normal.x + normal.y) throw new Error("Wrong");
freeze
if (freeze.x + freeze.y) throw new Error("Wrong")
seal
if (seal.x + seal.y) throw new Error("Wrong")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
normal
freeze
seal
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 18 on iOS 18.5
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
normal
150711568.0 Ops/sec
freeze
181922976.0 Ops/sec
seal
303803968.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its test cases. **Benchmark Definition JSON** The benchmark definition is a JSON object that contains information about the benchmark to be performed. It includes: * `Name`: A unique name for the benchmark, which in this case is "Object.freeze vs Object.seal (only property access)". * `Description`: An optional description of the benchmark, which is empty in this case. * `Script Preparation Code`: A JavaScript code snippet that prepares the script to be executed. In this case, it defines three objects: `normal`, `freeze`, and `seal`, each with two properties (`x` and `y`) initialized to 0. **Individual Test Cases** The benchmark consists of three individual test cases: 1. **`normal`**: This test case checks if the sum of `x` and `y` in the `normal` object is non-zero using an `if` statement that throws an error if the condition is true. 2. **`freeze`**: Similar to the previous test case, but this time it uses the `Object.freeze()` method to seal the `freeze` object, which also has two properties (`x` and `y`) initialized to 0. The goal is to check how different browsers handle property access on a frozen object. 3. **`seal`**: Another similar test case that checks how browsers handle property access on an object sealed with `Object.seal()`. **Options Compared** In this benchmark, the following options are being compared: * Using `Object.freeze()` vs using `Object.seal()`: Both methods prevent property assignment to an object's properties. However, `Object.freeze()` also prevents deletion of a property from the object, whereas `Object.seal()` only restricts assignment and addition of new properties. **Pros and Cons** Here are some pros and cons for each approach: * **`Object.freeze()`**: + Pros: Provides more protection against unwanted modifications to an object's properties. + Cons: May be overkill if you only need to prevent property assignment, as it also prevents deletion of properties. Additionally, `Object.freeze()` can introduce performance overhead due to the additional checks performed on the object. * **`Object.seal()`**: + Pros: Provides protection against unwanted modifications to an object's properties while still allowing for some flexibility (e.g., deleting a property). + Cons: May not be enough protection if you need to ensure that certain properties are always present or have specific values. **Library Usage** None of the provided test cases use any external libraries. **Special JS Features/Syntax** There is no mention of special JavaScript features or syntax in the benchmark definition or individual test cases. **Other Alternatives** Some alternative approaches could be: * Using `Object.assign()` to prevent property assignment * Using a library like Lodash's `freeze()` function to seal an object * Implementing custom protection mechanisms using techniques like proxy objects or getter/setter functions However, these alternatives are not being tested in this specific benchmark.
Related benchmarks:
Destructure from Object.seal vs Object.freeze vs normal
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?