Array push then join

Benchmark created on


Setup

const emails = [];
for (let i = 0; i <= 100000; i++) {
	emails.push(`foo+${i}@example.com`);
}

Teardown

emails.length = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
Array push then join
let emailsArr = [];
for (const email of emails) {
	emailsArr.push(email);
}
const emailsCsv = emailsArr.join(',');
ready
String concat on-the-fly
let emailsCsv = '';
for (const email of emails) {
	if (emailsCsv.length === 0) {
		emailsCsv += ',';
	}
	emailsCsv += email;
}
ready

Revisions

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