How can I run JMH benchmarks inside my existing project using JUnit tests? The official documentation recommends making a separate project, using Maven shade plugin, and launching JMH inside the main
method. Is this necessary and why is it recommended?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
I've been running JMH inside my existing Maven project using JUnit with no apparent ill effects. I cannot answer why the authors recommend doing things differently. I have not observed a difference in results. JMH launches a separate JVM to run benchmarks to isolate them. Here is what I do:
Add the JMH dependencies to your POM:
Note that I've placed them in scope
test
.In Eclipse, you may need to configure the annotation processor manually. NetBeans handles this automatically.
Create your JUnit and JMH class. I've chosen to combine both into a single class, but that is up to you. Notice that
OptionsBuilder.include
is what actually determines which benchmarks will be run from your JUnit test!JMH's annotation processor seems to not work well with compile-on-save in NetBeans. You may need to do a full
Clean and Build
whenever you modify the benchmarks. (Any suggestions appreciated!)Run your
launchBenchmark
test and watch the results!Runner.run
even returnsRunResult
objects on which you can do assertions, etc.