java 計時工具 用戶性能測試



/** 
* @Description: 計時工具:單位毫秒
* 用於性能測試
* @author Adobe Chow
* @date 2017年11月16日 上午11:50:18 
*  
*/
public class TimerUtils {
private static long startTime = -1;
/** 
* @Description: 開始計時
*/
public static void start(){
startTime = System.currentTimeMillis();
}

/** 
* @Description: 關閉並返回時間間隔
*/
public static long stop(){
if(startTime<0){
System.out.println("start開關未開啓 ");
return startTime;
}
long timeSpace = System.currentTimeMillis()-startTime;
System.out.println("時間間隔: "+timeSpace+" 毫秒");
return timeSpace;
}

public static void main(String[] args) {
//開始計時
TimerUtils.start();

String str = "";
for (int i = 0; i < 10000; i++) {
str = str + "11"+i;
}
//關閉並返回時間間隔
TimerUtils.stop();
}

}



控制檯輸出:



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章