Concise way to compare runtime of alternate implementations
Keith Newman
knewman at techempower.com
Thu Feb 26 19:11:22 UTC 2015
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Both the Enum and abstract implementations did the trick. Thanks
Aleksey and Dmitry!
Best,
Keith
On 2/25/2015 11:33 PM, Aleksey Shipilev wrote:
> Ah yes, dang it, I misread Keith's requirement.
>
> Yes, you can parametrize over different implementations, either
> with enum as Dmitry outlined below, or you may use inheritance:
>
> http://hg.openjdk.java.net/code-tools/jmh/file/bdfc7d3a6ebf/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_24_Inheritance.java
>
>
>
...and do the @Setup in each particular concrete subclass.
>
> -Aleksey.
>
> On 02/26/2015 10:16 AM, vyazelenko at yahoo.com wrote:
>> Hi Keith,
>>
>> If benchmarks are the same for every impl then you can simply
>> add parameter which will tell which impl to instantiate. Then
>> inside the @Setup method you'll create target instance based on
>> that parameter: @Param private ImplType type; @Setup(Level.Trial)
>> public void setUp() { switch(implType): case Impl1:
>> impl=Utils.myClass1(); break; case Impl2: impl=Utils.myClass2();
>> }
>>
>> @Benchmark public boolean contains_val() { return
>> impl.contains(val); }
>>
>> This approach requires that your impls have common interface by
>> which you'll refer to them in the benchmarks.
>>
>> Regards, Dmitry
>>
>> Sent from my iPhone
>>
>>> On Feb 26, 2015, at 07:20, Aleksey Shipilev
>>> <aleksey.shipilev at oracle.com> wrote:
>>>
>>> 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.
>>>
>>>
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAEBAgAGBQJU72/aAAoJEPig1oaTe12jUkIQAL5OO9L+fmRf4gBPoReZAz0m
kgPSS55TsVchLcVCIz7Mr3pUXrt0DXPdbU8yw40Ed/U8CAWSEXiV8x00UKrtLdsG
Z6KIzpKHggav/Fyyd95jtm9STofQo3kK/V20O0ROR0DY4dgHutFf7CbK2baxQ/sa
H3AhQKlL/DmKPiaQNJGb/6RocWsrQF1zHMAfHnlYIxmhW0I8l3LMuT2jssLNDXNx
sQ8k14lcozSLSDIg2V7vW5VHaeBJlb8XdRp5WFSfg/chZKHRBMhjz7oNVne7ewK3
e0xac0kVdZ/sZ7U+6GeuAVF6/uhM9CA1v75hCj+iVhzUwhCUrDev63j5Wum7Nq/e
Ea+BhJhNxpbyz5GG6F5YDem1rJmm3BUfwjxC/jLBbr1Ok/915lRGks6SpiDfhRIu
yC5gRaagIU+Y7WckiLt/8qw/EOKyZYO06qe8b0UUkisYQi4IS7Wyb8Yxujq8LJI1
dPuelt39fs8YdmkLDiBiriB5nPF23yMQvDLw3q1Ecwy8tsEdxl6l1inGlji4mnKS
2NwfRtwNaocMRm+6nJ0VoKIVu9LRt9Qvj+Y7cmcdCyxnPgsZ6iQYKQwvDdFb0+MQ
RQnRMupUymbxltvSWW9kiJCfeyaUlUTliavFG96tnVS3pHRLdXb9FHoiLX6Qg6Zw
mv2HnckUBJNUqrcO6aW/
=bFDL
-----END PGP SIGNATURE-----
More information about the jmh-dev
mailing list