Array.push perf tests (v2)

Revision 2 of this benchmark created on


Setup

const vals = Array.from({length: 1_000}, () => Math.random()).map((x, idx) => ({name: idx, value: x}));
const myArray = Array.from({length: 1_000}, () => Math.random()).map((x, idx) => ({name: idx * 2, value: x}));

Test runner

Ready to run.

Testing in
TestOps/sec
forloop
vals.forEach((v) => {
	if (!myArray.some(x => x.name === v.name)) {
		myArray.push(v);	
	}
});
ready
concat
const existingNames = new Set(myArray.map(x => x.name));

const toAdd = vals.filter(v => !existingNames.has(v.name));

const myNewArray = myArray.concat(toAdd)
ready

Revisions

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