JMH java基准测试

 

maven依赖

    <dependencies>
        <dependency>
            <groupId>org.openjdk.jmh</groupId>
            <artifactId>jmh-core</artifactId>
            <version>${jmh.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjdk.jmh</groupId>
            <artifactId>jmh-generator-annprocess</artifactId>
            <version>${jmh.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jmh.version>1.0</jmh.version>
        <javac.target>1.6</javac.target>
        <uberjar.name>benchmarks</uberjar.name>
    </properties>

 

命令行方式:

  生成测试项目

mvn archetype:generate \
          -DinteractiveMode=false \
          -DarchetypeGroupId=org.openjdk.jmh \
          -DarchetypeArtifactId=jmh-java-benchmark-archetype \
          -DgroupId=org.sample \
          -DartifactId=test \
          -Dversion=1.0

  打包

$ cd test/
$ mvn clean install

  执行, 

java -jar target/benchmarks.jar
java -jar target/benchmarks.jar -h //查看帮助信息

 

插件方式 

   idea插件

  插件会影响执行效果,但最多不会超过 2.2%

A brief research shows that benchmark results are affected, but not that much. The whole research is described in Research results. 
Long story short, the maximum means difference observed was 2.2%.

  

 

 

 

 

参加链接:

http://openjdk.java.net/projects/code-tools/jmh/

上一篇:OpenJDK下SpringBoot使用HttpSession时页面打开卡住


下一篇:如何下载JDK