El Marce
El Marce

Reputation: 3344

JMH, Microbenchmark part of the code

I would like to see if there is a way to tell JMH to measure JUST one particular method mithin all the methods called from the microbenchmark.

I would like to automate the creation of microbenchmarks using unit tests as base, so I don't have to build the microbenchmarks manually. In my research I have a large codebase over wich I do some automatic modifications expecting them to have an impact in performance. So far I have 1200 places in the code that gets modified. The automation is needed since we want to provide a framework that does the transformations and then automatically measure the impact of the transformations.

Here JMH: don't take into account inner method time a solution is provided, however I would have to separate manually the code in the @Start method and that does not seems to practicall to do with 1200 test cases...

Upvotes: 1

Views: 285

Answers (1)

Aleksey Shipilev
Aleksey Shipilev

Reputation: 18847

You can't, because it is not microbenchmarking.

Microbenchmarking implies measuring the performance characteristics of (an isolated) code segment as whole, given the exact environment setup, including preparing the data, and feeding it into the method/system of choice, measuring the end-to-end metrics. That was JMH is destined to do: payload is marked with @Benchmark, and it is measured indivisibly, with a possibility to phase away setup and teardown work.

Measuring a selected payload method among other executing payload methods would be confusing at best, anyhow: without knowing what else is going on in the system, those individual metrics tell you nothing. In other words, what you want requires profiling instruments, that are able to dissect the individual parts' impact on the metrics. This is something that profilers and Application Performance Management systems are destined to do.

Upvotes: 2

Related Questions