使用

  • Concatenation Operator (+)
  • String concat method – concat(String str)
  • StringBuffer append method – append(String str)
  • StringBuilder append method – append(String str)

进行性能测试。

环境 win7 32位, cpu双核2.5GHZ,2G内存。

测试代码如下:

    private final static int OUTER_ITERATION = 10;
private final static int INNER_ITERATION = 50000; /**
* @param args
*/
public static void main(String[] args) {
String addTestStr = "";
String concatTestStr = "";
StringBuffer concatTestSb = null;
StringBuilder concatTestSbu = null; for (int outerIndex = 0; outerIndex < OUTER_ITERATION; outerIndex++) {
StopWatch stopWatch = new LoggingStopWatch("StringAddConcat");
addTestStr = "";
for (int innerIndex = 0; innerIndex < INNER_ITERATION; innerIndex++)
addTestStr += "*";
stopWatch.stop();
} for (int outerIndex = 0; outerIndex < OUTER_ITERATION; outerIndex++) {
StopWatch stopWatch = new LoggingStopWatch("StringConcat");
concatTestStr = "";
for (int innerIndex = 0; innerIndex < INNER_ITERATION; innerIndex++)
concatTestStr.concat("*");
stopWatch.stop();
} for (int outerIndex = 0; outerIndex < OUTER_ITERATION; outerIndex++) {
StopWatch stopWatch = new LoggingStopWatch("StringBufferConcat");
concatTestSb = new StringBuffer();
for (int innerIndex = 0; innerIndex < INNER_ITERATION; innerIndex++)
concatTestSb.append("*");
stopWatch.stop();
} for (int outerIndex = 0; outerIndex < OUTER_ITERATION; outerIndex++) {
StopWatch stopWatch = new LoggingStopWatch("StringBuilderConcat");
concatTestSbu = new StringBuilder();
for (int innerIndex = 0; innerIndex < INNER_ITERATION; innerIndex++)
concatTestSbu.append("*");
stopWatch.stop();
} }

测试结果:
Performance Statistics   2010-04-08 06:16:00 - 2010-04-08 06:16:30

Tag Avg(ms) Min Max Std Dev Count
StringAddConcat 9355.4 7860 10046 547.7 10
StringBufferConcat 3.5 0 5 2.3 10
StringBuilderConcat 2.0 0 5 2.4 10
StringConcat 3.1 0 6 2.5 10

最新文章

  1. UWP开发之ORM实践:如何使用Entity Framework Core做SQLite数据持久层?
  2. OpenLiveWriter代码插件
  3. 【神器】vimum在浏览器中键盘操作选择、复制、粘贴,键盘党的最爱
  4. oracle 授权
  5. MSSQL常用函数
  6. jquery源码
  7. 用Python的smtp模块发邮件的示例
  8. HDU 3333 Turing Tree (树状数组)
  9. String.Format格式说明(转)
  10. AutoCAD使用技巧
  11. linux 下网站压力测试工具webbench
  12. Tomcat Java内存溢出 PermGen space 解决方案
  13. pku2104
  14. Hadoop新生报到(一) hadoop2.6.0伪分布式配置详解
  15. Springmvc_validation 效验器
  16. Servlet 执行流程 生命周期 ServletConfig 线程安全
  17. BZOJ_4004_[JLOI2015]装备购买_线性基
  18. Softmax函数详解与推导
  19. CF685B Kay and Snowflake 贪心
  20. super和this的区别

热门文章

  1. word2vec使用说明(google工具包)
  2. [转]7个高性能JavaScript代码高亮插件
  3. 【The Expendables】团队博客目录
  4. 1017关于EXPLAIN的语法
  5. openwrt刷机后配置PPPOE上网方法
  6. [转]Filter实现处理中文乱码,转义html标签,过滤敏感词
  7. [转]Servlet 中文乱码问题及解决方案剖析
  8. EditText 几种显示方式,固定行数,自适应行数
  9. 【BZOJ 3083】遥远的国度
  10. 【BZOJ 2818】gcd 欧拉筛