I have a spring boot
application which I want to benchmark using JMH
. Any reference for this integration will be useful.
Benchmarking spring boot application with JMH
11.3k views Asked by Soumyajit Swain At
2
There are 2 answers
1
On
There is no need to spin up the Spring context to benchmark a method. In fact, I'm not sure what are you really trying to benchmark here as the method implementation isn't changing. If all you want is to time the method, it's a whole lot simpler and less error-prone to call the method directly. If you want to benchmark the startup time under varying circumstances, see my answer here.
The solution was quite than easy than I thought. The important part is to start the spring-boot application when the benchmark is getting initialized. Define a class level variable for configuration context and give a reference to it during setup of the benchmark. Make a call to the bean method inside the benchmark.