如何使用Java 12的Microbenchmark Suite?

Jac*_* G. 5 java benchmarking microbenchmark jmh java-12

根据JEP 230:Microbenchmark Suite,存在Java 12内置的微基准套件。JEP解释说它基本上是JMH,但无需使用Maven / Gradle明确依赖它。但是,它没有指定如何访问属于该套件的类/注释来执行基准测试。

我的问题是:

  • module-info.java要使用此套件,我是否需要一个特定的Java模块?
  • 该套件的类/注释位于什么包中?
  • 此套件与JMH之间有什么主要区别吗?

Jor*_*nee 7

Your interpretation is incorrect. The JEP says:

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.

i.e. this is not necessarily something that makes it into a JDK distribution, just something that is added to the source code repository to make it easier to run benchmarks on JDK code. Though, to be fair, the fact that it's listed as one of the JDK 12 'features' seems a tad misleading.

The benchmarks can be run by using the OpenJDK build system. Once you have cloned the OpenJDK source code from http://hg.openjdk.java.net/jdk/jdk/ (or another repository that includes the JEP), you can run benchmarks e.g. by using:

make test TEST="micro:java.lang.reflect"
Run Code Online (Sandbox Code Playgroud)

基准位于\test\micro\目录中。另请参见文档:http : //hg.openjdk.java.net/jdk/jdk/raw-file/ddfb658c8ce3/doc/testing.html#microbenchmarks

另外,这要求您在生成构建配置时指定JMH及其依赖项:

bash configure --with-jmh="/path/to/jmh/jars"
Run Code Online (Sandbox Code Playgroud)

所需的jar是:commons-math3jmh-corejmh-generator-annprocessjopt-simple

  • 并不是第一次将某些东西作为新Java版本的功能列出,而只是内部实现细节,例如“代码清除”或“最终将所有源代码存储库合并为一个”等。同样,该列表也没有使常规Java功能与参考实现(又称为HotSpot / OpenJDK)的功能有所不同。 (3认同)
  • @Holger是的,JDK 12页面上列出的内容似乎是来自JBS的具有fixVersion 12的JEP的转储:https://bugs.openjdk.java.net/browse/JDK-8209093?jql=issuetype%20% 3D%20JEP%20AND%20fixVersion%20%3D%20%2212%22 (2认同)