/**
* @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();
}
}
控制檯輸出: