<div dir="ltr"><div>Hi,</div><div><br></div><div>I want to benchmark "insert a batch of records to the database" scenario,</div><div>and I want to use batches with varying sizes.</div><div><br></div><div>Ideally I would like to have something like the following:</div><div><br></div><div>Random batchSize; // state variable</div><div><br></div><div>@Benchmark<br></div><div>Object insertBatch(Infra infra) {</div><div>    int size = rnd.nextInt(10000);</div><div>    infra.opsPerInvocation(size); // <-- I want this instead of having a fixed @OperationsPerInvocation</div><div>    var ps = ...prepareStatement(...);</div><div>    for(int i=0; i<size; i++) {</div><div>        ps.addbatch(...);</div><div>    }</div><div>    return ps.executeBatch();</div><div>}</div><div><br></div><div>Is it possible with JMH?</div><div><a class="gmail_plusreply"><br></a></div><div>The reason I want to have dynamic batch size is to mimic the regular application workload.</div><div>The application typically uses varying batch sizes, thus the implementation should handle that.</div><div><br></div><div>However, if I use fixed-size batches in tests (e.g. 100, 1000), then the implementation could cheat.</div><div>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,</div><div>thus it would be super-optimal for 100 yet it won't show the same performance in production.</div><div><br></div><div>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".</div><div>Is it something that exists in JMH or can it be added if missing?</div><div><br></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Vladimir</div></div></div></div></div>