Set vs Map (v6)

Revision 6 of this benchmark created on


Preparation HTML

	

Setup

const data =
	Array(16384)
		.fill(0)
		.map((_, i) => BigInt(i % 128));

const data_sorted =
	data.slice()
		.sort();

Test runner

Ready to run.

Testing in
TestOps/sec
Map
const xy = new Map();

data.forEach(v => xy.set(v, true));

const unique_items = Array.from(xy.keys());

data_sorted.map(v => xy.has(v));
ready
Set
const sxy = new Set();

data.forEach(v => sxy.add(v));

const unique_items = Array.from(sxy.values());

data_sorted.map(v => sxy.has(v));
ready
Object
const xy = {};

data.forEach(v => (xy[v] = true));

const unique_items = Array.from(Object.keys(xy));

data_sorted.map(v => (xy[v] === true));
ready
Array / for-loop
const sxy = [];

data.forEach(v => sxy.push(v));

const unique_items = Array.from(Object.values(sxy));

for (let i = 0; i < data_sorted.length; ++i) {
	for (let j = 0; j < sxy.length; ++j) {
		if (sxy[j] === data_sorted[i]) {
			break;
		}
	}
}
ready
Array / includes
const sxy = [];

data.forEach(v => sxy.push(v));

const unique_items = Array.from(Object.values(sxy));

data_sorted.map(v => sxy.includes(v));
ready

Revisions

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