Hands-on experiment

Now that we have Eclipse Oxygen installed, you can run a quick test to determine if JMH is working on your development computer. Start by creating a new Maven project as illustrated in the following screenshot:

New Maven project

Next, we need to add a dependency. We can do this by editing the pom.xml file directly with the following code:

<dependency>
<groupId>org.openjdk.jmh</groupId>
  <artifactId>jmh-core</artifactId>
<version>0.1</version>
</dependency>

Alternatively, we can click the Add... button on the New Maven project dialog window (see the previous screenshot) to enter the data in a dialog window, as shown in the following screenshot. Using this form updates the pom.xml file with the preceding code:

Dependency selection

Next, we need to write a class that contains a JMH method. This is just as an initial test to confirm our recently updated development environment. Here is sample code you can use for your test:

package com.packt.benchmark.test.com.packt.benchmark.test;
import org.openjdk.jmh.Main;

public class Test {
public static void main(String[] args) {
Main.main(args);
}
}

We can now compile and run our very simple test program. The results are provided in the Console tab, or the actual console if you are using the command line. Here is what you will see:

JMH test results
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset