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();
}

}



控制台输出:



猜你喜欢

转载自blog.csdn.net/zdb1314/article/details/78549846
今日推荐