per-invocation setup for mutable data
Aleksey Shipilev
shade at redhat.com
Wed Dec 14 11:27:30 UTC 2016
On 12/13/2016 09:57 PM, Travis Downs wrote:
> 1) Using Level.Invocation on the @Setup method so that the array can be
> randomized (more likely this is a simple arraycopy() of the existing array
> into the destination) before every invocation - but there are a laundry
> list of reasons in the javadoc why you don't want to use this.
>
> 2) Make a copy of the array to be sorted in the benchmark method and sort
> the copy. Now the copy time will be included in the benchmark, which is
> non-negligible. I could have another benchmark that *only* did the copy and
> then subtract out the difference, I guess...
These are the only good options. Pick
> Any other good options? Of course, if the sort() method is not
> data-dependent, the randomization may not matter, but most are...
You have listed the only viable options. None of them are excellent, but there
is no other way. This was captured in sample some time ago ;)
See:
http://hg.openjdk.java.net/code-tools/jmh/file/8b06fb523516/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_38_PerInvokeSetup.java
Thanks,
-Aleksey
More information about the jmh-dev
mailing list