How do I time a method's execution in Java?

前端 未结 30 2702
北荒
北荒 2020-11-21 11:15
  1. How do I get a method\'s execution time?
  2. Is there a Timer utility class for things like timing how long a task takes, etc?

Mos

30条回答
  •  独厮守ぢ
    2020-11-21 12:03

    You can try this way if just want know the time.

    long startTime = System.currentTimeMillis();
    //@ Method call
    System.out.println("Total time [ms]: " + (System.currentTimeMillis() - startTime));    
    

提交回复
热议问题