Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.freeze vs Object.seal - Access only
(version: 0)
Comparing performance of:
normal vs freeze vs seal
Created:
3 years 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
normal.x; normal.y;
freeze
freeze.x; freeze.y;
seal
seal.x; seal.y;
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:
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
normal
1672168448.0 Ops/sec
freeze
1669197696.0 Ops/sec
seal
1672064128.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **What is being tested?** The provided JSON represents a benchmark test that compares the performance of three different approaches: 1. `Object.freeze()`: This method creates an immutable object, meaning its properties cannot be modified after creation. 2. `Object.seal()`: This method creates a partially frozen object, which can have some properties frozen while allowing others to be modified. The benchmark tests the execution time of accessing the `x` and `y` properties on these objects using different methods: * Accessing individual property names (`normal.x`, `freeze.x`, etc.) * Property name as an array (`normal['x']`, `freeze['x']`, etc.) **Options compared** The two main options being compared are: 1. **Immutable object**: An object created with `Object.freeze()` cannot be modified after creation, making it a good choice when data is not expected to change. 2. **Partially frozen object**: An object created with `Object.seal()` can have some properties frozen while allowing others to be modified, which can provide a balance between flexibility and immutability. **Pros and Cons** * **Immutable object (`Object.freeze()`)** + Pros: Ensures data is not modified accidentally or intentionally, reduces side effects in functions that return objects. + Cons: Can lead to slower execution when accessing properties using bracket notation (`normal['x']`). * **Partially frozen object (`Object.seal()`)** + Pros: Allows for some flexibility while still ensuring certain properties are protected from modification. + Cons: May lead to unexpected behavior if the wrong property is modified accidentally or intentionally. **Library and purpose** In this benchmark, no libraries are explicitly mentioned. However, `Object` and its methods (`freeze()`, `seal()`) are part of the built-in JavaScript API. **Special JS feature or syntax** There is a special way to access object properties using bracket notation: `[property_name]`. For example, `normal['x']` instead of just `normal.x`. **Other alternatives** Some alternative approaches to testing this scenario could include: * Using other methods to freeze or seal objects, such as `Object.prototype.freeze()` or `Object.assign()`. * Creating custom classes or prototypes with similar behavior. * Comparing performance using different data types (e.g., numbers, strings, booleans). Keep in mind that these alternatives might not directly address the specific question being asked and might require significant changes to the benchmark test.
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?