1. 程式人生 > >How can I count the time it takes a function to complete in Java?

How can I count the time it takes a function to complete in Java?

要知道 一個 function 需要執行多少個 ms, 用下面的程式就可以了,滿方便的。

long startTime = System.currentTimeMillis();

doReallyLongThing();

long endTime = System.currentTimeMillis();

System.out.println("That took " + (endTime - startTime) + " milliseconds");