Concise way to compare runtime of alternate implementations

Aleksey Shipilev aleksey.shipilev at oracle.com
Thu Feb 26 06:20:49 UTC 2015


Hi Keith,

On 02/26/2015 04:28 AM, Keith Newman wrote:
> I have two implementations of the same custom class:
> 
> private List<String> a = Util.myCustomClass();
> private List<String> b = Util2.myCustomClass();
> 
> and would like to compare the runtime of each of their functions (which
> all have the same name). Currently, my benchmark tests look like:
> 
> @Benchmark
> public boolean contains_val_a() {
>    return a.contains(val);
> }
> 
> @Benchmark
> public boolean contains_val_b() {
>   return b.contains(val);
> }
> 
> And I repeat this parallel structure for 25 or so different functions
> (writing each function twice because of the two implementations). Is
> there a way for me to only write the 25 @Benchmark functions and have
> jmh run each function for both implementations?

No, because JMH cannot guess what inputs to put into the method.
Figuring out what inputs are sensible to benchmark with depends on the
nature of the object under test, and I don't think it could be / should
be specified within the harness.

Thanks,
-Aleksey.




More information about the jmh-dev mailing list