Are ES6 template literals faster than string concatenation?

前端 未结 5 1244
予麋鹿
予麋鹿 2020-11-27 13:37

Does HTML code generation run measurably faster in modern browsers when using string concatenation or template literals in ES6?

For example:

String con

5条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 14:21

    I think that the benchmark above is not useful. The result of interpolation or concatenation hasn't used. So yes, concatenation is pretty fast, because no string coping there and result string have only links to the parent strings. But if you'll try out the result string or compare with another one, the string will be serialized to plane string and, yes it will take some time. So interpolation could be more effective for CPU and memory usage then concatenation in real cases.

提交回复
热议问题