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

Posted in :

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

long startTime = System.currentTimeMillis();

doReallyLongThing();

long endTime = System.currentTimeMillis();

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

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *