How can I count the time it takes a function to complete in Java? Posted on 2017-10-312017-10-31 要知道 一個 function 需要執行多少個 ms, 用下面的程式就可以了,滿方便的。 long startTime = System.currentTimeMillis(); doReallyLongThing(); long endTime = System.currentTimeMillis(); System.out.println("That took " + (endTime - startTime) + " milliseconds");