Time units

In order to gain greater fidelity in benchmark output, we can designate a specific unit of time, listed here from shortest to longest:

  • NANOSECONDS
  • MICROSECONDS
  • MILLISECONDS
  • SECONDS
  • MINUTES
  • HOURS
  • DAYS

In order to make this designation, we simply add the following code to our @Benchmark line:

    @Benchmark @BenchmarkMode(Mode.Average)     @OutputTimeUnit(TimeUnit.NANOSECONDS)

In the preceding example, we have designated the average mode and nanoseconds as the time unit.

Get Java 9: Building Robust Modular Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.