Reputation: 169
Sometimes we have to perform same DB operation multiple times within a loop. How can I compute the execution time for each operation using JMH?
public void applyAll(ArrayList<parameter_type> lists) {
for(parameter_type param : lists) {
saveToDB(param);
}
}
How can I compute the execution time for saveToDB(param) for each time it is being executed/called?
Upvotes: 1
Views: 356
Reputation: 2939
As @RafaelWinterhalter said, this type of calls are prone to give misleading results in benchmarks. But if you still want to try, then:
@State(Scope.Thread)
object to restore this list to an array and have a loop counter variable there. @Benchmark public int test1_saveToDB(MyState state) { saveToDB(state.params[state.i]); return state.i++; }
Upvotes: 0
Reputation: 43997
DB operations are really nothing to microbenchmark. Their will depend on multiple things that are quite impossible to isolate.
As for using parameters, have a look at this answer that explains the use of the @Param
annotation.
Upvotes: 1