您的位置:首页 > 编程语言 > Java开发

java 计时工具 用户性能测试

2017-11-16 12:38 411 查看
/** 

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

}

控制台输出:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: