var to0 = {};
var to1 = {};
var to2 = {};
var wm = new WeakMap();
var sy = Symbol();
var prop = 'aaa'
wm.set(to1, 1);
to1[sy] = 1;
to2[prop] = 1;
wm.set(to0, 1);
to0[sy] = 1;
let r = wm.get(to1);
let r = to1[sy];
to2[prop] = 1;
let r = to2[prop];
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
WeakMap set | |
Symbol Property set | |
WeakMap get | |
Symbol Property get | |
String Property set | |
String Property get |
Test name | Executions per second |
---|---|
WeakMap set | 11643148.0 Ops/sec |
Symbol Property set | 12471522.0 Ops/sec |
WeakMap get | 11771086.0 Ops/sec |
Symbol Property get | 12468970.0 Ops/sec |
String Property set | 12397484.0 Ops/sec |
String Property get | 12486915.0 Ops/sec |
Let's break down the provided benchmark and explain what is being tested.
Benchmark Overview
The benchmark measures the performance of three different property access methods: WeakMap, Symbol Property, and String Property (using bracket notation). The test case consists of six individual tests:
Options Compared
The benchmark compares the performance of three different approaches:
Pros and Cons
Library Used
In this benchmark, the WeakMap
data structure is used from the built-in JavaScript API. No external libraries are required.
Special JS Features/Syntax
The benchmark uses Symbol properties, which is a relatively new feature in JavaScript introduced in ECMAScript 2015 (ES6). It provides faster and more efficient way to access properties compared to traditional string-based notation.
Other Alternatives
For those who may be interested in exploring alternative approaches, here are some other options:
In summary, this benchmark measures the performance of three different property access methods: WeakMap, Symbol Property, and String Property (using bracket notation). The results can help developers understand which approach is best suited for their specific use cases, considering factors like performance, memory management, and browser compatibility.