Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object freeze vs normal obj access
(version: 0)
Comparing performance of:
Freeze vs No freeze
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const baseObj = { ...[ Array.from({ length: 1000 }, () => Math.random().toString(16).slice(2)) ] } var obj = Object.assign({}, baseObj); var frozen = Object.freeze(Object.assign({}, baseObj));
Tests:
Freeze
for (let i = 0; i < 1000; i++) { frozen[i] }
No freeze
for (let i = 0; i < 1000; i++) { obj[i] }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Freeze
No freeze
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:144.0) Gecko/20100101 Firefox/144.0
Browser/OS:
Firefox 144 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Freeze
1110167.4 Ops/sec
No freeze
1103457.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll explain the benchmark in detail. **Benchmark Overview** The provided JSON represents a JavaScript microbenchmarking test case, which compares the performance of two approaches: freezing an object versus normal object access. **Benchmark Definition** The benchmark definition consists of two test cases: 1. "Freeze": This test case uses the `Object.freeze()` method to freeze an object and then iterates over its properties using a `for` loop. 2. "No freeze": This test case does not use `Object.freeze()` and instead directly accesses the object's properties in a `for` loop. **Options Compared** The two options being compared are: * **Freezing an object**: Using `Object.freeze()` to create an immutable object that cannot be modified after creation. * **Normal object access**: Directly accessing an object's properties without freezing it. **Pros and Cons of Each Approach** * **Freezing an object:** + Pros: - Provides a predictable and stable environment for benchmarking, as the object's state is frozen in time. - Can help identify performance bottlenecks related to object mutation. + Cons: - May introduce additional overhead due to the creation of a new object instance and the use of `Object.freeze()`. * **Normal object access:** + Pros: - Does not incur additional overhead compared to normal object access. - Can provide more realistic performance measurements, as it reflects real-world usage scenarios. + Cons: - May introduce variability in performance results due to the dynamic nature of JavaScript objects. **Library and Purpose** The `Object.assign()` method is used to create a shallow copy of an object. The purpose of using this method is to create a new object instance that can be modified independently from the original object, which is then frozen using `Object.freeze()`. **Special JS Feature or Syntax** There are no special JavaScript features or syntax mentioned in this benchmark. **Other Considerations** When interpreting the benchmark results, consider the following: * The `ExecutionsPerSecond` value represents the number of iterations performed per second on each test case. * The benchmark was run on a Chrome 128 browser instance with a Mac OS X 10.15.7 operating system and desktop device platform. * The "No freeze" test case may exhibit higher performance due to the absence of overhead introduced by freezing an object. **Alternatives** Other alternatives for comparing object access performance could include: * Using `Object.create()` or other techniques to create a new object instance with a similar structure to the original object. * Using a testing framework like Jest or Mocha, which provide built-in support for benchmarking and performance measurement.
Related benchmarks:
Object freeze
obj creation
Object.freeze vs Object.seal vs Native
Freeze vs no freeze
frozen VS unfrozen object iteration times
Comments
Confirm delete:
Do you really want to delete benchmark?