Search code examples
spring-bootjmhjunit-jupiter

add JMH an existing spring boot project


I have tried multiple tutorials to make a poc using jmh inside my test package but always faced: No matching benchmarks. Miss-spelled regexp. My latest code:

        <dependency>
            <groupId>org.openjdk.jmh</groupId>
            <artifactId>jmh-core</artifactId>
            <version>1.35</version>
        </dependency>
        <dependency>
            <groupId>org.openjdk.jmh</groupId>
            <artifactId>jmh-generator-annprocess</artifactId>
            <version>1.35</version>
        </dependency>

I downloaded 'JMH Java Microbenchmark Harness' plugin ( I tried also JMHack)

created these two classes


public class TestBenchmark
{

    @Benchmark
    public void init() {
        // Do nothing
    }

}

and

public class BenchmarkRunner {
    public static void main(String[] args) throws Exception {
        org.openjdk.jmh.Main.main(args);
    }
} 

And it's not working,

I will list couple of articles I already tried

from stackoverflow

This tutorial

medium article

I think I must create a new project but It would be great if I could apply it to an existing project


Solution

  • Once I did simple integration of JMH with Spring Boot, you can find an example in https://github.com/stsypanov/spring-boot-benchmark