Is there an equivalent to @BeforeAll in JMH(Java Microbenchmark Harness), Level.Trial is not working

22 Views Asked by At

Hello and good morning from Germany!

Since my English isn’t very good, I can only offer you a ChatGPT translation of my question.

Here’s the issue: I’m using the JMH Tool to benchmark a SpringBoot application. Before calling my @Benchmark methods, I have a @Setup method that is also annotated with @(Level.Trial). According to the JMH documentation, this means the following:

Trial level: To be executed before/after each run of the benchmark. Despite my doubts about my English, I’ve had it translated, and I keep arriving at the conclusion that the following assertion should not fail:

   @Setup(Level.Trial)
   public void loginProcess()
   {
      setupCalls++; //This is a static field
      Assertions.assertEquals(1, setupCalls);
   }
   @Benchmark
   public void doSomething()
   {
      doSomething();
   }

In my case, the assertion fails because JMH calls the @Setup method again after the first benchmark method (before starting the second benchmark method). I’m completely confused. Do you have any idea what’s going on?

Thanks in fortune

0

There are 0 best solutions below