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

前端 未结 30 3209
北荒
北荒 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:57

    I basically do variations of this, but considering how hotspot compilation works, if you want to get accurate results you need to throw out the first few measurements and make sure you are using the method in a real world (read application specific) application.

    If the JIT decides to compile it your numbers will vary heavily. so just be aware

提交回复
热议问题