JMH Benchmark

Nasimuzzaman Himel nasimuzzaman.iit.du at gmail.com
Sun Apr 23 06:18:59 UTC 2017


I am stuck with my maven project. Please see the below scenario first.

I need to Benchmark apply(Migratable m) method. This method is being called
multiple times from a for loop from another method
doUpdate(Collection<migratable>
applicableUpdates).

Actually, I need to compute the execution time for saveToDatabase(m) from
method apply(Migratable m) for each time it is being executed.

How can I do that? please provide exact code if possible.


class Test {

public void applyAll() {
....................
....................
Collection<migratable> applicableUpdates =
SomeOtherClass.getApplicableUpdates(int index);
doUpdate(applicableUpdates);

}

@Benchmark
public void apply(Migratable m) {
....................
saveToDatabase(m);
....................
}

private void doUpdate(Collection<migratable> applicableUpdates) throws
Exception {
for (Migratable m : applicableUpdates) {
try {

apply(m);

} catch (Exception e) {
logger.error("Falid to apply migration {}" + m, e);
throw e;
}
}
}
}


More information about the jmh-dev mailing list