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

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

    JEP 230: Microbenchmark Suite

    FYI, JEP 230: Microbenchmark Suite is an OpenJDK project to:

    Add a basic suite of microbenchmarks to the JDK source code, and make it easy for developers to run existing microbenchmarks and create new ones.

    This feature arrived in Java 12.

    Java Microbenchmark Harness (JMH)

    For earlier versions of Java, take a look at the Java Microbenchmark Harness (JMH) project on which JEP 230 is based.

提交回复
热议问题