String join perf

Benchmark created on


Setup

function makeBigStr(length) {
    let result = '';
    const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ()/?><';
    const charactersLength = characters.length;
    let counter = 0;
    while (counter < length) {
        result += characters.charAt(Math.floor(Math.random() * charactersLength));
        counter += 1;
    }
    return result;
}
const arr = Array(10_000).map(() => makeBigStr(2*(1<<10)));

Test runner

Ready to run.

Testing in
TestOps/sec
1
const str = arr.reduce((acc, s) => acc + s, '');
ready
2
let str = '';
for(let i = 0; i < arr.length; ++i) {
	str += arr[i];
}
ready
3
var str = '';
var len = arr.length;
for(var i = 0; i < len; ++i) {
	str += arr[i];
}
ready
4
const str = arr.join('');
ready

Revisions

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