Map copy vs Proxy

Benchmark created on


Setup

const map = new Map();
for (let i = 0; i < 10000; i++) {
	map.set(`key${i}`, Math.random())
}

const proxy = (map) => {
	return new Proxy(map, {
		get(obj, prop) {
			const value = Reflect.get(obj, prop);
			if (typeof value === 'function') {
				return value.bind(obj);
			}
			return value;
		},
		has(obj, prop) {
			return Reflect.has(obj, prop);
		},
		ownKeys(obj) {
			return Reflect.ownKeys(obj);
		},
		getOwnPropertyDescriptor(obj, prop) {
			return Reflect.getOwnPropertyDescriptor(obj, prop);
		}
	})
}

Test runner

Ready to run.

Testing in
TestOps/sec
Copy map
const map2 = new Map(map);
map2.has('key');
ready
Create Proxy
const map2 = proxy(map);
map2.has('key');
ready

Revisions

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