String Concatenation Performance Test

Benchmark created on


Description

Benchmarking various string concatenation methods, including "+ operator", template literals, Array.join(), String.concat(), and Array.reduce().

Setup

const iterations = 10000; // Number of iterations for consistency
const word = "Hello"; // The string to concatenate

Test runner

Ready to run.

Testing in
TestOps/sec
Using + Operator
let result = '';
for (let i = 0; i < iterations; i++) {
    result += word;
}
ready
Using Template Literals
let result = '';
for (let i = 0; i < iterations; i++) {
    result = `${result}${word}`;
}
ready
Using Array.join()
const parts = [];
for (let i = 0; i < iterations; i++) {
    parts.push(word);
}
const result = parts.join('');
ready
Using String.concat()
let result = '';
for (let i = 0; i < iterations; i++) {
    result = result.concat(word);
}
ready
Using Array.reduce()
const parts = Array(iterations).fill(word);
const result = parts.reduce((acc, curr) => acc + curr, '');
ready

Revisions

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