After all that theory, here is a basic benchmark developed with JMH:
public class QuoteMicrobenchmark { @Benchmark public void compute() { // }}
In this case, we have a single benchmark scenario called compute. It doesn't use any states and didn't customize any thread or fork count.
In practice, this will not be enough and you will often need a state to get a service. So, it will more look like this:
public class QuoteMicrobenchmark { @Benchmark public void compute(final QuoteState quoteState) { quoteState.service.findByName("test"); } @State(Scope.Benchmark) public static class QuoteState { private QuoteService service; @Setup public void setup() { service = new QuoteService(); } }}
Here, we created a nested ...