Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Sealed object access vs ordinary object access
(version: 1)
Comparing performance of:
Sealed object access vs Ordinary object access
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
const obj = {a: 1, b: 2, c: 3, d: 4}; const sealedObj = Object.seal({a: 1, b: 2, c: 3, d: 4, __proto__: null}); let v = null;
Tests:
Sealed object access
v = sealedObj.a; v = sealedObj.b; v = sealedObj.c; v = sealedObj.d;
Ordinary object access
v = obj.a; v = obj.b; v = obj.c; v = obj.d;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Sealed object access
Ordinary object access
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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Sealed object access
3210107.8 Ops/sec
Ordinary object access
3223505.5 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The benchmark described compares the performance of accessing properties from two types of JavaScript objects: a standard (ordinary) object and a sealed object. ### Benchmark Details 1. **Benchmark Setup**: - Two objects are created: - `obj`: An ordinary JavaScript object. - `sealedObj`: A sealed object created using `Object.seal()`. - Both objects have the same properties: `a`, `b`, `c`, and `d`. 2. **Test Cases**: - **Ordinary Object Access**: - The benchmark accesses properties `a`, `b`, `c`, and `d` from the ordinary object. - ```javascript v = obj.a; v = obj.b; v = obj.c; v = obj.d; ``` - **Sealed Object Access**: - This test accesses the same properties from the sealed object. - ```javascript v = sealedObj.a; v = sealedObj.b; v = sealedObj.c; v = sealedObj.d; ``` ### Results Overview - The results show that the ordinary object access has an execution rate of approximately 3,223,505.5 executions per second, while the sealed object access is slightly lower at about 3,210,107.75 executions per second. ### Pros and Cons of Each Approach 1. **Ordinary Object**: - **Pros**: - Very straightforward and flexible object structure. - Allows dynamic property addition or deletions during runtime. - **Cons**: - Slightly slower in scenarios where property manipulation is frequent, due to the dynamic properties and potential prototype lookup. 2. **Sealed Object**: - **Pros**: - Useful for preventing any new properties from being added to the object, improving encapsulation and potentially enhancing performance when property access is stable and predictable. - Helps maintain data integrity by not allowing changes to the object's structure. - **Cons**: - Slight performance overhead in accessing properties compared to ordinary objects, particularly in cases where the sealed state is not utilized. - Non-dynamic; if the module or requirements evolve, sealed objects can be restrictive. ### Alternative Considerations - Another alternative would be to use frozen objects created with `Object.freeze()`, which not only prevents adding new properties but also ensures existing properties cannot be modified. However, accessing properties from frozen objects may exhibit a similar performance profile to sealed objects, likely with a lower execution rate due to additional constraints on mutability. - Pure ECMAScript objects, arrays, and maps can also serve as data structures, depending on the use case. For strict scenarios where performance and integrity of data shape are critical, utilizing sealed or frozen objects could be beneficial while balancing flexibility against speed based on specific application requirements. ### Conclusion Overall, this benchmark helps to understand the performance implications of using sealed objects versus ordinary objects in JavaScript, providing insights into when each approach might be more advantageous based on specific coding needs and project requirements.
Related benchmarks:
El bencho 333
Constructor vs object literal 2
Object access vs destructing
func vs object vs symbol
Assignment of value vs Destructuring an object ee
Assignment of values vs Destructuring of object
Object.create(null) vs {} unknown property
JavaScript spread operator check
Frozen object access vs ordinary object access
Comments
Confirm delete:
Do you really want to delete benchmark?