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

前端 未结 30 2695
北荒
北荒 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 11:45

    Also We can use StopWatch class of Apache commons for measuring the time.

    Sample code

    org.apache.commons.lang.time.StopWatch sw = new org.apache.commons.lang.time.StopWatch();
    
    System.out.println("getEventFilterTreeData :: Start Time : " + sw.getTime());
    sw.start();
    
    // Method execution code
    
    sw.stop();
    System.out.println("getEventFilterTreeData :: End Time : " + sw.getTime());
    

提交回复
热议问题