String的连接操作之自定义工具类及与+,cancat性能比较
用Javascript面向对象方式,自己编写一个Javascript函数,来进行字符串连接操作.
函数代码如下:
运行,且看结果:
运行结果次数用+ 用concat 用自定义方法1 use + cost time ==109 use concat cost time ==141use stringBuffer cost time ==622 use + cost time ==250 use concat cost time ==328use stringBuffer cost time ==783 use + cost time ==250 use concat cost time ==266use stringBuffer cost time ==62
总结:
用自定义的方法,平均耗时是用+的33%,是用concat的27%,所以三种方法中最耗时的是concat,其次是+.效率最高的应该是自定义的方法