Annotation API Fail?
Jan Bernitt
jaanbernitt at gmail.com
Mon Nov 13 10:59:14 UTC 2017
Hi!
I'm new to JMH but if I don't totally miss something the annotation API
design is ...well...awful.
Didn't anyone want to name a benchmark something other than a method name?
Method names are constrained. Why not allowing to override it?
@Benchmark(name="+")
There are a lot of cases where the operation we measure is much better
summarised with a string that would be illegal as a method name.
Didn't anyone try to measure both average time and throughput for a method?
Of course I want average time in another time unit than throughput.
@OutputTimeUnit and @BenchmarkMode don't make much sense as separate
annotations.
Or I am missing something here.
Why not add more properties to @Benchmark?
@Benchmark(mode: Throughput, outputTimeUnit: SECONDS)
If I want multiple modes I use multiple @Benchmark annotations.
@Benchmark(mode: Throughput, outputTimeUnit: SECONDS)
@Benchmark(mode: AverageTime, outputTimeUnit: NANOSECONDS)
I could name them differently or not. If name is used for one and the other
is blank that name should be used for both IMO.
While we are at it. @Measurement, @OperationsPerInvocation, @Group and
maybe even @GroupThreads all could become properties of @Benchmark. Again I
might want different values for different measurements/modes/runs.
All properties can have their defaults (like now) so that @Benchmark still
can be used without any arguments. To specify class wide defaults the
@Benchmark is annotated on class level.
If this is to confusing for someones taste wrap them in a @Defaults
annotation
@Defaults({
@Benchmark(mode: Throughput, outputTimeUnit: SECONDS),
@Benchmark(mode: AverageTime, outputTimeUnit: NANOSECONDS)
})
Then almost everything can be done with just the one @Benchmark annotation
what is also much easier to document, comprehend and discover. And you can
get rid of code.
Cheers,
Jan
More information about the jmh-dev
mailing list