I'm trying to benchmark an asynchronous operation that has the form:
void op(Callback cb);
I could benchmark using:
@Benchmark
void issueOp(BenchState state) {
state.svc.op(nullCb);
}
but that only measures the time to issue the operation, not the completion time.
@Benchmark
void issueOp(BenchState state) {
final CountDownLatch latch = new CountDownLatch(1);
Callback signalCb = new Callback() {
public void complete() {
latch.countDown();
}
};
state.svc.op(signalCb);
signalCb.await();
}
does measure the completion time, but with only one op queued up at a time.
I would really like something like:
@AsyncBenchmark
void issueOp(BenchState state, final BenchmarkCompletion bc) {
Callback cb = new Callback() {
void complete() {
bc.complete();
}
};
state.svc.op(cb);
}
where BenchmarkCompletion is something provided by JMH to indicate that the operation is complete.
Is there anything like this in JMH?