Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.freeze vs Object.seal
(version: 0)
Comparing performance of:
normal vs freeze vs seal
Created:
7 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
var t = normal.x; normal.x = normal.y; normal.y = t;
freeze
var t = freeze.x; freeze.x = freeze.y; freeze.y = t;
seal
var t = seal.x; seal.x = seal.y; seal.y = 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:
4 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:145.0) Gecko/20100101 Firefox/145.0
Browser/OS:
Firefox 145 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
normal
446934624.0 Ops/sec
freeze
18357344.0 Ops/sec
seal
449828640.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark and explain what's being tested, compared, and the pros/cons of each approach. **Benchmark Overview** The benchmark compares the performance of three JavaScript objects: `normal`, `freeze`, and `seal`. All three objects have two properties, `x` and `y`, initialized to 0. The benchmark is designed to test how fast each object can be modified. **Test Cases** There are three test cases: 1. **Normal Object**: The benchmark starts by assigning a value to `normal.x` (i.e., `t = normal.x;`) and then updating both `x` and `y` properties in sequence (i.e., `normal.y = t;`). 2. **Frozen Object**: Similar to the first test case, but this time the object is frozen using `Object.freeze()` before running the benchmark. 3. **Sealed Object**: Similar to the second test case, but this time the object is sealed using `Object.seal()` before running the benchmark. **Library Used** The library used in this benchmark is `Object`. Specifically, it uses the following methods: * `Object.freeze()`: Creates a new frozen object by copying the specified object's properties and sealing them. The original object remains unchanged. * `Object.seal()`: Creates a new sealed object by copying the specified object's properties and making some of them non-configurable (i.e., cannot be modified directly). Like `Object.freeze()`, the original object remains unchanged. **Special JS Features/Syntax** There are no special JavaScript features or syntax used in this benchmark, but it does use ES6+ syntax (`let` and `const`). **Pros/Cons of Each Approach** Here's a brief summary of each approach: * **Normal Object (no modification)**: This is the baseline performance. Modifying an object requires creating a new one, which can be costly in terms of memory allocation. + Pros: Easy to implement, doesn't require any special libraries or syntax. + Cons: Can be slow for large objects due to frequent memory allocations. * **Frozen Object (modified)**: + Pros: Faster than normal objects since the object's properties are sealed and cannot be modified directly. + Cons: If the object needs to be updated, it must first be thawed using `Object.parse()` or other methods, which can be slow. * **Sealed Object (modified)**: + Pros: Faster than normal objects since some of the object's properties are non-configurable and cannot be modified directly. + Cons: If an attempted modification causes a runtime error, it can be slower than using a frozen object. **Other Alternatives** If you're looking for alternative approaches to benchmarking, consider: * **Procedural programming**: Instead of creating objects, use arrays or other data structures to store and update values. * **Prototype-based programming**: Create new objects by cloning existing ones instead of using `Object.create()` or similar methods. Keep in mind that these alternatives may not provide the same level of control over object behavior as the approaches used in this 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?