Set.prototype.add vs Array.prototype.push performance

Benchmark created on


Setup

const objs = [];
for (let i = 0; i < 100; i++) objs.push({});

Test runner

Ready to run.

Testing in
TestOps/sec
set add
const a = new Set();
for (let i = 0; i < 100; i++) a.add(objs[i]);
for (let i = 0; i < 100; i++) a.add(objs[i]);
console.log(a.has(objs[0]))
ready
array push
const a = [];
for (let i = 0; i < 100; i++) a.push(objs[i]);
for (let i = 0; i < 100; i++) a.push(objs[i]);
console.log(a[0])
ready

Revisions

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