Custom and not-constant "Operations per invocation" (Re: JMH 1.15)

Lev Serebryakov lev at serebryakov.spb.ru
Mon Oct 3 17:51:24 UTC 2016


On 03.10.2016 20:12, Lev Serebryakov wrote:

>>  *) @AuxCounters improvements. Note this is still a very much
>> experimental API. That said, it makes sense to improve it a little more:
>> now it handles more field/method types, has new counting mode "events"
>> that does not normalize to time, and does not require reset between
>> iterations. This API change is backwards-compatible. See the RFE:
>>    https://bugs.openjdk.java.net/browse/CODETOOLS-7901810
>> ...and new Javadoc:
>  Looks like, it is way to implement custom "operations per invocation"
> metric, am I right?
> 
>  Problem I have at hands looks like this: I benchmark implementation,
> which could do batching of low-level operations. To make benchmark more
> "realistic" I choose size of batch on each invocation at random (really,
> from pre-filled big array of random numbers, as random generators, even
> bad ones, are slow). So, each benchmark invocation could be counted as
> different number of operations, from 1 to, say, 16. and default JMH's
> "average time per invocation" is not very meaningful in this situation,
> as I need to know time per basic operation.
> 
>  Looks like "@AuxCounters" is solution, am I right? I only need to count
> real number of basic operations, and I'm done!
 It seems to work, but I don't understand how result is combined from
different threads. Again, I have benchmark which contains of two threads
in one group, doing different work. If I have same "counter" state class
(Scope.Thread, of course) I get 19ns/count ("op"). If I have two
different classes, I get 16ns/count at each thread. It looks strange and
I could not do mental model what happens in case when each thread
increments logically-the-same counter (in thread-local state). If all
instances of this counter are summed up, it should be ~2 times faster
than splitted counters (because combined counter is sum of splitted
ones, and splitted counters are roughly the same). But it is slightly
slower!

-- 
// Black Lion AKA Lev Serebryakov



More information about the jmh-dev mailing list