无意中看见c++ string与 c char字符串效率的一些争论。
因而就工作中常用到的语句, 自己写了一些比较公平的测试代码, 基本可以看出string 比 c style字符串高效很多。
测试结果如下:
C style1 time is: 78 ms.length: 2999997
C style2 time is: 79 ms.length: 2999997
C++ style1 time is: 16 ms.length: 2999997
C++ style2 time is: 15 ms.length: 2999997
其中多次测试时发现c++ string给出的时间有时候为0, 可能与string 内部设计相关
通过实验对比了C++ string与C风格字符串在拼接操作中的效率,结果显示C++ string在处理大规模字符串时更为高效。
2319

被折叠的 条评论
为什么被折叠?



