2

Usually when I want to test performance I am using System.nanoTime() function before running code and after it and then I am doing a a subtraction. Recently I noticed that people are using

@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)

which it is a part of JMH in openjdk.

We are using Oracle jdk. I wonder if there is a similar tool or if there is another way for building, running, and analysing nano/micro/milli/macro benchmarks instead of writing System.nanoTime.

Govan
  • 2,079
  • 4
  • 31
  • 53

2 Answers2

4

From the JMH website:

JMH is a Java harness for building, running, and analysing nano/micro/milli/macro benchmarks written in Java and other languages targetting the JVM.

So JMH should work regardless of whether you have OpenJDK installed or Oracle's JDK. OpenJDK and Oracle's JDK are both an implementation of a language that targets the JVM, so I don't see an issue.

Just as a note -- just because JMH is maintained as part of OpenJDK doesn't mean that it is meant exclusively for OpenJDK.

awksp
  • 11,764
  • 4
  • 37
  • 44
  • 2
    True. JMH works perfectly well for Oracle JDK, or any other Hotspot-derived runtime. – Aleksey Shipilev Jun 04 '14 at 20:35
  • I don't find any guide for installing JMH for Hotspot @user3580294 : @ Aleksey Shipilev? Is there some guide for it? – Govan Jun 05 '14 at 09:24
  • 1
    @Govan Check out the [website](http://openjdk.java.net/projects/code-tools/jmh/). You'll need maven, apparently. – awksp Jun 24 '14 at 12:41
2

Use JMH for performance testing include dependeny in maven as below

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

Example can be found in http://psy-lob-saw.blogspot.in/2013/05/using-jmh-to-benchmark-multi-threaded.html

sakumar
  • 489
  • 5
  • 11