Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
normal vs Object.freeze vs Object.seal performance
(version: 0)
Comparing performance of:
normal vs freeze vs seal
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
normal
var normal = { x: 0, y: 0 };
freeze
var freeze = Object.freeze({ x: 0, y: 0 });
seal
var seal = Object.seal({ x: 0, y: 0 });
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:
15 days ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:149.0) Gecko/20100101 Firefox/149.0
Browser/OS:
Firefox 149 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
normal
1570829184.0 Ops/sec
freeze
16191517.0 Ops/sec
seal
14877647.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its options. **Benchmark Overview** The benchmark, named "normal vs Object.freeze vs Object.seal performance", compares the performance of three different approaches: using an ordinary object (`var normal`), freezing an object (`var freeze = Object.freeze({ ... })`), and sealing an object (`var seal = Object.seal({ ... })`). The goal is to determine which approach provides the best performance. **Options Compared** The three options compared are: 1. **Normal object**: An ordinary object created using the `var normal` syntax. 2. **Frozen object**: An object frozen in place using the `Object.freeze()` method, as seen in the "freeze" test case. 3. **Sealed object**: An object sealed for non-configurable properties using the `Object.seal()` method, as seen in the "seal" test case. **Pros and Cons of Each Approach** 1. **Normal Object**: * Pros: Easy to create and access properties. * Cons: The entire object can be modified if a single property is changed. 2. **Frozen Object**: * Pros: All properties are read-only, making it difficult for an attacker to modify the object's behavior. * Cons: Creating a frozen object requires additional code to ensure all properties are set before freezing. 3. **Sealed Object**: * Pros: Some properties can be modified without breaking the seal, but others remain frozen. * Cons: Not as secure as freezing, as some properties can still be changed. **Library and Purpose** In this benchmark, the `Object` library is used to create and manipulate objects. The `Object.freeze()` method creates a new object with all enumerable properties set to "not writable" and all inherent and accessed properties set to "not configurable", while the `Object.seal()` method sets all own enumerable properties of an existing object as non-configurable. **Special JS Feature or Syntax** There are no special features or syntax used in this benchmark beyond what's required for JavaScript objects. **Other Considerations** When choosing between these approaches, consider the trade-offs between security, ease of use, and performance: * If security is a top priority, using an object frozen in place (`Object.freeze()`) may be the best choice. * If you need to allow some properties to be modified while still maintaining others, sealing an object (`Object.seal()`) might be more suitable. * If ease of use is paramount and performance is not a concern, creating an ordinary object using `var normal` might be sufficient. **Alternatives** If you're looking for alternative approaches, consider: 1. **Creating objects with prototype chains**: By setting up a custom prototype chain, you can achieve similar behavior to sealing or freezing without using built-in methods. 2. **Using WeakMaps or WeakSets**: These data structures allow for more flexible and dynamic management of object properties compared to traditional JavaScript objects. These alternatives might be suitable in specific use cases where the performance differences between these options aren't as critical, but they also come with additional complexity and potential security implications.
Related benchmarks:
Array.forEach vs Object.keys().forEach
Object.keys/Object.values/Object.entries
Data Properties vs. Accessor Properties vs. Getter / Setter Methods vs Proxy
Empty an object in JavaScript (with baseline)
Object.freeze vs Object.seal (only property access)
Comments
Confirm delete:
Do you really want to delete benchmark?