1. 程式人生 > 其它 >Python numpy 入門系列 08 高階索引

Python numpy 入門系列 08 高階索引

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 = "";
        double
start = 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)); } }