O'Reilly logo

Java EE 8 High Performance by Romain Manni-Bucau

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Integrating JMH with JUnit

There is no official JUnit integration of JMH. In spite of that, it is not that hard to do it yourself. There are lots of possible designs, but in the context of this book we will do the following:

  • Our integration will go through a JUnit runner
  • The benchmark classes will be identified by extracting the nested classes of the test class which will avoid using any scanning to find the benchmark classes or explicit listing
  • We will introduce an @ExpectedPerformances annotation to be able to add assertions based on the execution

Structurally, a microbenchmark test using this structure will look like this:

@RunWith(JMHRunner.class)public class QuoteMicrobenchmarkTest {    @ExpectedPerformances(score = 2668993660.)    public ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required