Can OperationsPerInvocation vary for each invocation?
Vladimir Sitnikov
sitnikov.vladimir at gmail.com
Thu Jul 3 09:25:55 UTC 2025
Hi,
I want to benchmark "insert a batch of records to the database" scenario,
and I want to use batches with varying sizes.
Ideally I would like to have something like the following:
Random batchSize; // state variable
@Benchmark
Object insertBatch(Infra infra) {
int size = rnd.nextInt(10000);
infra.opsPerInvocation(size); // <-- I want this instead of having a
fixed @OperationsPerInvocation
var ps = ...prepareStatement(...);
for(int i=0; i<size; i++) {
ps.addbatch(...);
}
return ps.executeBatch();
}
Is it possible with JMH?
The reason I want to have dynamic batch size is to mimic the regular
application workload.
The application typically uses varying batch sizes, thus the implementation
should handle that.
However, if I use fixed-size batches in tests (e.g. 100, 1000), then the
implementation could cheat.
For instance, if I use say 100 for the batch size, the implementation could
cache a "insert statement with 100 entries" statement at the server-side,
thus it would be super-optimal for 100 yet it won't show the same
performance in production.
I would like to create a JMH test that would be able to ensure the
implementation does not hard-code against say "the latest values".
Is it something that exists in JMH or can it be added if missing?
Vladimir
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jmh-dev/attachments/20250703/ecc70af5/attachment.htm>
More information about the jmh-dev
mailing list