有没有一个命令在java中测量执行时间? [英] Is there a command in java to measure the execution time?
本文介绍了有没有一个命令在java中测量执行时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在java中有一个命令来测量执行时间?
Is there a command in java to measure the execution time ?
像
System.out.println(execution.time);
。
推荐答案
这里是一个完整的, a>
Here is a complete and little modified example on how you could do that:
public class ExecutionTimer {
private long start;
private long end;
public ExecutionTimer() {
reset();
start = System.currentTimeMillis();
}
public void end() {
end = System.currentTimeMillis();
}
public long duration(){
return (end-start);
}
public void reset() {
start = 0;
end = 0;
}
public static void main(String s[]) {
// simple example
ExecutionTimer t = new ExecutionTimer();
for (int i = 0; i < 80; i++){
System.out.print(".");
}
t.end();
System.out.println("\n" + t.duration() + " ms");
}
}
这篇关于有没有一个命令在java中测量执行时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文