我编写了一个程序,现在我想计算程序从头到尾的总运行时间。
我怎样才能做到这一点?
使用System.nanoTime获取当前时间。
long startTime = System.nanoTime();
.....your program....
long endTime = System.nanoTime();
long totalTime = endTime - startTime;
System.out.println(totalTime);
上面的代码以纳秒为单位打印程序的运行时间。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句