Discussion: CODETOOLS-7901222 - Enable benchmarks to have configurable Operation unit

Staffan Friberg staffan.friberg at oracle.com
Fri Dec 19 19:42:05 UTC 2014


Hi,

Wanted to discuss the RFE I just created and think could be useful.
https://bugs.openjdk.java.net/browse/CODETOOLS-7901222


Today all benchmarks will have ops/TimeUnit or TimeUnit/op.

For some benchmarks it would be a nice feature to be able to express the 
Operation to be more specific to what is actually measured.

An example would be a benchmark working on a byte[] and to better 
understand the performance of the benchmark the output could be 
bytes/TimeUnit or TimeUnit/byte, which would be more inline in what the 
benchmark actually tries to measure.

A suggested approach would to have an annotation allow the user to set 
the Operation unit.

Something similar to this.

     @Benchmark
     @OperationUnit(singular = "byte")
     @OperationsPerInvocation(64 * 1024)
     public void measureBytes() {
         random.nextBytes(bytes);
     }

     @Benchmark
     @OperationUnit(singular = "foot", plural = "feet")
     @OperationsPerInvocation(64 * 1024)
     public void measureDistance() {
         random.nextBytes(bytes);
     }


Here is a proof of concept patch, far from done, so nothing to really 
review for code quality etc yet.

http://cr.openjdk.java.net/~sfriberg/CODETOOLS-7901222/webrev.00

An option could also be to not look up the unit dynamically during 
runtime, but simply hardcode it as part of the benchmark generation as 
changing the operations unit probably doesn't make much sense from the 
command line. This would probably allow for a much smaller patch as well.


Would JMH users find this useful?

//Staffan


More information about the jmh-dev mailing list