Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
WeakMap vs Symbol Property 900
(version: 0)
Comparing performance of:
WeakMap set vs Symbol Property set vs WeakMap get vs Symbol Property get
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var to0 = {}; var to1 = {}; var wm = new WeakMap(); var sy = Symbol(); wm.set(to1, 1); to1[sy] = 1;
Tests:
WeakMap set
for(let i=900;--i;) wm.set(to0, 1);
Symbol Property set
for(let i=900;--i;) to0[sy] = 1;
WeakMap get
for(let i=900;--i;) {let r = wm.get(to1);}
Symbol Property get
for(let i=900;--i;) {let r = to1[sy];}
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
WeakMap set
Symbol Property set
WeakMap get
Symbol Property get
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
WeakMap set
16791.4 Ops/sec
Symbol Property set
18412.7 Ops/sec
WeakMap get
16242.6 Ops/sec
Symbol Property get
18481.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the benchmark and explain what's being tested. **Benchmark Context** The benchmark measures the performance of two different approaches: using `WeakMap` (a built-in JavaScript object that stores mappings of keys to values, with the key being an object that can be garbage collected) and using a symbol property (a unique identifier for an object's property). **Options Compared** In this benchmark, we have four test cases: 1. **WeakMap set**: This test case measures the performance of setting a value in `WeakMap`. 2. **Symbol Property set**: This test case measures the performance of setting a value using a symbol property. 3. **WeakMap get**: This test case measures the performance of getting a value from `WeakMap`. 4. **Symbol Property get**: This test case measures the performance of getting a value using a symbol property. **Pros and Cons** * **WeakMap**: + Pros: Efficient use of memory, garbage collection, and reduced overhead. + Cons: May not be suitable for use cases that require direct access to underlying data. * **Symbol Property**: + Pros: Allows for fine-grained control over property access, can be used in conjunction with other features like getters and setters. + Cons: May introduce additional overhead due to symbol creation and resolution. **Library and Purpose** In this benchmark, we don't have a specific library being used. However, `WeakMap` is a built-in JavaScript object that provides an efficient way to store mappings of keys to values. **Special JS Feature or Syntax** The use of symbols (`sy`) in the benchmark introduces a special feature in JavaScript: symbol properties. Symbols are unique identifiers for objects' properties and provide an alternative to string-based property names. In this benchmark, symbols are used as property names to measure their performance compared to `WeakMap`. **Other Considerations** * **Garbage Collection**: The use of `WeakMap` relies on garbage collection to manage the keys and values. This can lead to unpredictable behavior if the system is under memory pressure. * **Overhead**: Both `WeakMap` and symbol properties introduce some overhead due to their creation and resolution. **Alternatives** If you need to measure performance for other use cases, consider alternatives like: * Using a different data structure, such as an object or an array. * Implementing your own data structure or cache. * Measuring the performance of alternative programming languages or frameworks.
Related benchmarks:
WeakMap vs Symbol Property
WeakMap vs Symbol Property v2
WeakMap vs Symbol Property vs String Property
WeakMap vs Symbol 2
Comments
Confirm delete:
Do you really want to delete benchmark?