assertions for jmh performance test results

Dmitry Timofeiev dmitry.timofeiev at gmail.com
Tue Dec 12 20:50:22 UTC 2017


Hi Vitaliy,

I may suggest two approaches to get the metrics:

(1) construct your performance tests parameters using an OptionsBuilder, 
run them and then analyze a Collection<RunResult> returned by 
org.openjdk.jmh.runner.Runner#run 
(http://hg.openjdk.java.net/code-tools/jmh/file/1ddf31f810a3/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_03_States.java#l125).

(2) run your tests using the CLI of the benchmarks.jar, but tell it to 
store the results in machine-readable format (AFAIR, CSV & JSON are 
supported):

 >  $ java -jar target/benchmark.jar -h

--------------------------------8<--------------------------------

-rf <type>                  Format type for machine-readable results. These
                               results are written to a separate file 
(see -rff).
                               See the list of available result formats 
with -lrf.
                               (default: CSV)
-------------------------------->8--------------------------------

There might be some other, possibly better, approaches.

Cheers,
Dmitry


On 12.12.17 22:16, Vitaliy Semochkin wrote:
> Thank you very much.
> Does it  provide an API so that a developer could get performance
> metrics not from logging?
> (If yes, it won't be difficult to write a JUnit test or a Rule).
>
> On Tue, Dec 12, 2017 at 10:13 AM, Nitsan Wakart <nitsanw at yahoo.com> wrote:
>> JMH does not offer this capability at the moment.
>>
>>
>>
>> On Monday, December 11, 2017 6:58 PM, Vitaliy Semochkin
>> <vitaliy.se at gmail.com> wrote:
>>
>>
>> Hi,
>>
>> Is there any way to create assertions for JMH performance test rests?
>>
>> E.g I expect avg time of execution to be no longer than T milliseconds
>> and I want the test to fail if the expectation is not met.
>>
>> Regards,
>> Vitaliy
>>
>>



More information about the jmh-dev mailing list