Accumulation vs Join

Benchmark created on


Setup

alpha = 'abcdefghijklmnopqrstuvwxyz'

Test runner

Ready to run.

Testing in
TestOps/sec
Accumulate with separator
txt = "";
for(let i = 0; i < alpha.length; i++) {
	if(i !== 0){ txt += " "; }; 
	txt += alpha[i];
}
console.log(txt);
ready
Array join
alphas = [];
for(let i = 0; i < alpha.length; i++) {
	alphas[i] = alpha[i];
}
console.log(alphas.join(' '));
ready
Array join pre-alloc
alphas = Array(alpha.length);
for(let i = 0; i < alpha.length; i++) {
	alphas[i] = alpha[i];
}
console.log(alphas.join(' '));
ready

Revisions

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