Fwd: Integrate JMH in existing maven project

Aleksey Shipilev ashipile at redhat.com
Mon Apr 17 09:46:51 UTC 2017


On 04/10/2017 02:23 PM, Nasimuzzaman Himel wrote:
> To: support at jenkov.com

Ha!

> Sir, I'm working on a maven project currently. I face some problem
> integrating JMH on my existing project. So I have got a few question. Hope
> you'll answer...
> 
> 1. How to integrate JMH in existing maven project?

Like any other Maven project? The JMH workspace has jmh-samples and
jmh-core-benchmarks that behave like any other project with JMH dependencies.

Depend on jmh-core and one of the jmh-*-generators, compile with generators
enabled (annprocess would be enabled automatically), pack everything up into a
JAR (important: with resources), done.

Better yet, just make the project from the Maven archetype, put it into your
multi-module project as separate module, hook up <dependency> on your project
artifacts.

> 2. How to Benchmark a method that takes parameters from another method (See
> below scenario)?

JMH does not know what instance of Migratable to call method with. How can it
know it? You have to have the Migratable field, initialize it in @Setup method
with the instance you want, and then call @Benchmark.

> I need to compute the execution time of apply(Migratable m) method for each
> time it is being called.
> 
> Note that Migratable is an interface.

...

Thanks,
-Aleksey




More information about the jmh-dev mailing list