这可不一定,这取决于实现。大量字符串拼接时,join 可以先把结果串的长度算出来才开始拷内容,避免反复重新分配内存。
当然现在 js 通常是直接用加号更快了。而 Python 至今仍然是 join 比加快。
Browser string optimizations have changed the string concatenation picture.
Firefox was the first browser to optimize string concatenation. Beginning with version 1.0, the array technique is actually slower than using the plus operator in all cases. Other browsers have also optimized string concatenation, so Safari, Opera, Chrome, and Internet Explorer 8 also show better performance using the plus operator. Internet Explorer prior to version 8 didn’t have such an optimization, and so the array technique is always faster than the plus operator.
【 在 ottffsse (nothing) 的大作中提到: 】
: 因为 google developers错了。
: 直接拼字符串:
: 1)string是primitive type, which is simple
: ...................
--
修改:vonNeumann FROM 211.99.222.*
FROM 211.99.222.*