如何计算我的程序的运行时间? [英] How to calculate the running time of my program?
本文介绍了如何计算我的程序的运行时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
如何计算方法在Java中的执行时间?
我写了一个程序,现在我想从开始到结束计算我的程序的总运行时间。
我怎么能这样做使用 System.nanoTime 获取当前时间。
long startTime = System.nanoTime( );
.....你的程序....
long endTime = System.nanoTime();
long totalTime = endTime - startTime;
System.out.println(totalTime);
以上代码以纳秒为单位打印程序的运行时间。
Possible Duplicate:
How do I time a method's execution in Java?
I wrote a program and now I want to calculate the total running time of my program from start to end.
How can I do this?
解决方案
Use System.nanoTime to get the current time.
long startTime = System.nanoTime();
.....your program....
long endTime = System.nanoTime();
long totalTime = endTime - startTime;
System.out.println(totalTime);
The above code prints the running time of the program in nanoseconds.
这篇关于如何计算我的程序的运行时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文