Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
Chrome 110
Windows
Desktop
2 years ago
Test name Executions per second
Concatenation 276.7 Ops/sec
Template strings 340.1 Ops/sec
Concatenating strings with template strings 308.5 Ops/sec
Concatenation without substring call 341.5 Ops/sec
Concat 1721.5 Ops/sec
Template 1705.1 Ops/sec
Script Preparation code:
x
 
var obj = {0:"test",1:"test",2:"test",3:"test"};
Tests:
  • Concatenation

     
    for (let i = 0; i < 10000; i++){
        let s = "";
        for (let j = 0; j < 4; j++){
            s += obj[j] + " - "; 
        }
        s = s.substring(0,s.length - 3);
    }
  • Template strings

     
    for (let i = 0; i < 10000; i++){
        let s = `${obj[0]} - ${obj[1]} - ${obj[2]} - ${obj[3]}`;
    }
  • Concatenating strings with template strings

     
    for (let i = 0; i < 10000; i++){
        let s = "";
        for (let j = 0; j < 2; j++){
            s += obj[j] + " - "; 
        }
        s += `${obj[2]} - `;
        s += `${obj[3]}`;
    }
  • Concatenation without substring call

     
    for (let i = 0; i < 10000; i++){
        let s = obj[0] + " - " + obj[1] + " - "  + obj[2] + " - " + obj[3];
    }
  • Concat

     
    for (let i = 0; i < 10000; i++){
        let s = "testtesttesttesttest" + obj[1] + " - ";
    }
  • Template

     
    for (let i = 0; i < 10000; i++){
        let s = `testtesttesttesttest ${obj[1]} - `;
    }