zoukankan      html  css  js  c++  java
  • String、StringBuffer、StringBuilder效率测试

    /**
    * @auto dh
    * @create 2020-03-25-15:16
    */
    public class StringTest {
    public static void main(String[] args) {
    long startTime = 0L;
    long endTime = 0L;
    String text = "";
    StringBuffer sf = new StringBuffer("");
    StringBuilder sl = new StringBuilder("");

    /*StringBuffer效率测试*/
    System.out.println("StringBuffer效率测试");
    startTime = System.currentTimeMillis();
    for (int i = 0; i < 20000; i++) {
    sf.append(String.valueOf(i));
    }
    endTime = System.currentTimeMillis();
    System.out.println(endTime - startTime);
    /*StringBuilder效率测试*/
    System.out.println("StringBuilder效率测试");
    startTime=System.currentTimeMillis();
    for(int i=0;i<20000;i++){
    sl.append(String.valueOf(i));
    }
    endTime=System.currentTimeMillis();
    System.out.println(endTime-startTime);
    /*String效率测试*/
    System.out.println("String效率测试");
    startTime=System.currentTimeMillis();
    for(int i=0;i<20000;i++){
    text+=i;
    }
    endTime=System.currentTimeMillis();
    System.out.println(endTime-startTime);
    }
    }
  • 相关阅读:
    mybatis的延时加载缓存机制
    mybatis03
    事务
    codeforces-200B
    codeforces-339B
    codeforces-492B
    codeforces-266B
    codeforces-110A
    codeforces-887B
    codeforces-69A
  • 原文地址:https://www.cnblogs.com/kukai/p/12566523.html
Copyright © 2011-2022 走看看