JAVA study notes _ get code program execution time

method one:

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

Method Two:

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

Method three:

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325723673&siteId=291194637