JAVA学习笔记_获取代码程序执行时间

方法一:

Date start = new Date();
...
...
...
Date end = new Date();
System.err.println("运行时间:  "+(end-start)+"ms")

方法二:

long startTime=System.currentTimeMillis();
...
...
...
long endTime=System.currentTimeMillis();
System.err.println("运行时间: "+(end-start)+"ms");

方法三:

long startTime=System.nanoTime();
...
...
...
long endTime=System.nanoTime();
System.err.println("运行时间: "+(end-start)+"ms");

猜你喜欢

转载自blog.csdn.net/icecoola_/article/details/79869622