Python numpy 入門系列 08 高階索引
阿新 • • 發佈:2022-03-18
import java.sql.Time; public class Javatest72 { /** * String和StringBuffer效能對比 * 練習1:寫程式碼測試字串拼接的效能,比如拼接10萬次 * 輸出結果: * String拼接時間:14863.0 * StringBuffer拼接時間:0.0 */ public static void main(String[] args) { String s = "abc"; String s2 = ""; doublestart = System.currentTimeMillis(); for (int i = 0; i < 100000; i++) { s2 += s; } double end = System.currentTimeMillis(); System.out.println("String拼接時間:" + (end - start)); StringBuffer s1 = new StringBuffer("abc"); StringBuilder s3 = new StringBuilder(""); double start1 = System.currentTimeMillis(); for (int i = 0; i < 100000; i++) { s3.append(s1); } double end1 = System.currentTimeMillis(); System.out.println("StringBuffer拼接時間:" + (end1 - start1)); } }