通过代码计算一段程序运行的时间

Posted yushaolin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过代码计算一段程序运行的时间相关的知识,希望对你有一定的参考价值。

 1 public class T1 {
 2     public static void main(String[] args) {
 3         long start=System.currentTimeMillis();
 4         long n=0;
 5         while(n<1000000000){
 6             n++;
 7         }
 8         System.out.print("运行时间为:");
 9         long end=System.currentTimeMillis();
10         System.out.println(end-start);
11     }
12 }

结果为:

技术分享图片

 

以上是关于通过代码计算一段程序运行的时间的主要内容,如果未能解决你的问题,请参考以下文章