DOM data storage

Benchmark created on


Description

Expando on the node versus an object in a WeakMap

Preparation HTML

<div id="node1">Node 1</div>
<div id="node2">Node 2</div>

Setup

const
	node1 = document.getElementById('node1'),
	node2 = document.getElementById('node2'),
	map = new WeakMap(),
	value = [];

node1._data = {};
map.set(node2, {});

Test runner

Ready to run.

Testing in
TestOps/sec
Expando
for (let i = 0; i < 10; i++) {
	node1._data.foo = `${i}`;
}
for (let i = 0; i < 10; i++) {
	value[i] = node1._data.foo;
}

ready
WeakMap
for (let i = 0; i < 10; i++) {
	map.get(node2).foo = `${i}`;
}
for (let i = 0; i < 10; i++) {
	value[i] = map.get(node2).foo;
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.