Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.freeze vs Object.seal with array
(version: 0)
Comparing performance of:
normal vs freeze vs seal
Created:
4 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var normal = [ 0, 0 ]; var freeze = Object.freeze([0, 0]); var seal = Object.seal([0, 0]);
Tests:
normal
var t = normal[0]; normal[0] = normal[1]; normal[1] = t;
freeze
var t = freeze[0]; freeze[0] = freeze[1]; freeze[1] = t;
seal
var t = seal[0]; seal[0] = seal[1]; seal[1] = t;
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:
8 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/142.0
Browser/OS:
Firefox 142 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
normal
384607904.0 Ops/sec
freeze
13601963.0 Ops/sec
seal
383551520.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested, compared, and the pros and cons of each approach. **Benchmark Overview** The test case compares three different approaches to creating an immutable object in JavaScript: 1. `Object.freeze()` 2. `Object.seal()` with an array 3. A non-immutable object (in this case, a regular array) **Options Compared** Here's what's being compared: * **Immutable vs Non-Immutable**: The test case measures the execution speed of assigning values to different parts of an object. + Pros of Immutable objects: Ensures data integrity and predictability. Cons: Can be slower due to the overhead of creating a new object. + Pros of Non-Immune objects: Faster execution, as assignments are simply updating existing properties. + Cons of Non-Immune objects: Data can become inconsistent if not handled carefully. * **Object Freeze vs Object Seal**: Both methods aim to create an immutable object, but they differ in how they achieve it. **Object Freeze** `Object.freeze()` creates a new, frozen object that cannot be modified. The test case measures the execution speed of assigning values to different parts of this frozen object. Pros: * Ensures data integrity and predictability. * Can help catch bugs earlier. Cons: * Slower due to the overhead of creating a new object. * Can lead to unnecessary memory allocation if objects are frequently reassigned. **Object Seal** `Object.seal()` creates an object that is not fully sealed (i.e., some properties can be modified), but still provides some level of immutability. The test case measures the execution speed of assigning values to different parts of this partially sealed object. Pros: * Faster execution, as assignments are simply updating existing properties. * Can provide a balance between immutability and performance. Cons: * Data can become inconsistent if not handled carefully. * May not be suitable for all use cases where data integrity is crucial. **Other Considerations** The test case also measures the impact of using an array (a non-immutable object) as a container for values. This helps to identify any differences in execution speed due to array vs object-based storage. **Library and Special JS Feature Usage** In this benchmark, no libraries or special JavaScript features are used beyond what's built into the JavaScript standard library. `Object.freeze()` and `Object.seal()` are standard methods for creating immutable objects in JavaScript. However, it's worth noting that some browsers may have additional features or optimizations that might affect the results of this benchmark. Additionally, other languages or frameworks may provide similar APIs for creating immutable objects.
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?