Skip to Content
Java EE 8 High Performance
book

Java EE 8 High Performance

by Romain Manni-Bucau
January 2018
Intermediate to advanced
350 pages
9h 7m
English
Packt Publishing
Content preview from Java EE 8 High Performance

Creating your first JMH benchmark

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java EE 8 Application Development

Java EE 8 Application Development

David R. Heffelfinger
Java 9 High Performance

Java 9 High Performance

Mayur Ramgir, Nick Samoylov
Java EE 8 Design Patterns and Best Practices

Java EE 8 Design Patterns and Best Practices

Rhuan Rocha, Joao Carlos Purificação

Publisher Resources

ISBN: 9781788473064Supplemental Content