Test name | Executions per second |
---|---|
Concatenation | 267.6 Ops/sec |
Template strings | 322.1 Ops/sec |
Concatenating strings with template strings | 293.5 Ops/sec |
Concatenation without substring call | 326.5 Ops/sec |
var obj = {0:"test",1:"test",2:"test",3:"test"};
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);
}
for (let i = 0; i < 10000; i++){
let s = `${obj[0]} - ${obj[1]} - ${obj[2]} - ${obj[3]}`;
}
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]}`;
}
for (let i = 0; i < 10000; i++){
let s = obj[0] + " - " + obj[1] + " - " + obj[2] + " - " + obj[3];
}