Skip to content

JMH (Java Microbenchamrk Harness) tests that you can run separately from other tests with Maven profile.

License

Notifications You must be signed in to change notification settings

peterszatmary/jmh-benchmark-in-profile-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jmh-benchmark-in-profile-demo

Build Status

Java Microbenchmark Harness (JMH) that runs with Junit and Maven.

Project is about how to run JMH benchmark tests from test scope with Maven separately from other test with maven profile.

Is the second version from project jmh-benchmark-demo

How to run other tests except benchmarks

Excluding the benchmark test source files from test compiling is done with maven-compiler-plugin. See the testExcludes configuration part with used pattern.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <compilerVersion>${java.version}</compilerVersion>
        <source>${java.version}</source>
        <target>${java.version}</target>
    </configuration>
    <!-- excluding benchmark test source java files from test compile phase -->
    <executions>
        <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
                <goal>testCompile</goal>
            </goals>
            <configuration>
                <testExcludes>
                    <exclude>**/benchmark/*Test.java</exclude>
                    <!-- add here more if you need exclude additional files -->
                </testExcludes>
            </configuration>
        </execution>
    </executions>
</plugin>

You can run other than benchmark test with command

mvn clean test

Output :

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.szatmary.peter.junittest.ClassicJunitTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.13 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

How to run just benchmark tests

Excluding is also done with maven-compiler-plugin. Excluded is everything except benchmark tests.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <compilerVersion>${java.version}</compilerVersion>
        <source>${java.version}</source>
        <target>${java.version}</target>
    </configuration>
    <!-- exclude tests, just benchmarks we need to have here -->
    <executions>
        <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
                <goal>testCompile</goal>
            </goals>
            <configuration>
                <testExcludes>
                    <exclude>**/junittest/*Test.java</exclude>
                    <!-- add here more if you need exclude additional files -->
                </testExcludes>
            </configuration>
        </execution>
    </executions>
</plugin>

You can run other than benchmark test with command

mvn clean test -P benchmark-test

Output :

Benchmark                   Mode  Cnt   Score   Error  Units
SampleBenchmarkTest.newWay  avgt    2  12.372          ms/op
SampleBenchmarkTest.oldWay  avgt    2  10.632          ms/op
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.857 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.193 s
[INFO] Finished at: 2017-03-05T09:21:02+01:00
[INFO] Final Memory: 16M/178M
[INFO] ------------------------------------------------------------------------

About

JMH (Java Microbenchamrk Harness) tests that you can run separately from other tests with Maven profile.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages