Are ES6 template literals faster than string concatenation?

前端 未结 5 1245
予麋鹿
予麋鹿 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条回答
  •  萌比男神i
    2020-11-27 14:37

    For a simple test with random numbers as string, both are coming so close in Chrome & FF

    Testing in Chrome 58.0.3029 / Windows 10

    String literals 2,996,883 ±2.36% fastest

    Operator (+) 3,054,078 ±2.01% fastest

    Concat function 2,659,391 ±2.35% 13% slower

    Testing in Firefox 53.0.2 / Windows 10

    String literals 1,923,835 ±1.52% fastest

    Operator (+) 1,948,503 ±1.13% fastest

    Concat function 1,810,857 ±1.81% 8% slower

    Test here at jsperf

提交回复
热议问题