Correct way too perform loops

Francesco Nigro nigro.fra at gmail.com
Thu Sep 7 09:34:46 UTC 2017


Ah I didn't mentioned that the code is rearranged from this example:
http://hg.openjdk.java.net/code-tools/jmh/file/a128fd4a5901/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_26_BatchSize.java
But what is worrying me is: I've used a batchsize that will let the offer
to be compiled (C2), while in the example it was a pretty low value
(<10000): how this could affect the measured throughput?Or there is any
assumption I'm doing about it that is wrong?

Cheers,
Francesco

Il giorno lun 4 set 2017 alle ore 11:25 Francesco Nigro <nigro.fra at gmail.com>
ha scritto:

> Hi guys!
>
> I've written a benchmark to find out the throughput of some single
> threaded Queues offer (with resizes and GC activity dependent by it) and
> I'm struggling to find out the proper way to do it.
> That's my attempt:
>
> private Deque<Long> q;
>
> public int chunkSize = 1024;
>
> @Setup(Level.Iteration)
> public void init() {
>    this.q = new ArrayDeque<>(chunkSize);
> }
>
> @Benchmark
> @Warmup(iterations = 5, batchSize = 100_000)
> @Measurement(iterations = 5, batchSize = 100_000)
> @OperationsPerInvocation(100_000)
> public Object offer() {
>    q.offer(VALUE);
>    return q;
> }
>
> @TearDown(Level.Iteration)
> public void clean() {
>    q.clear();
> }
>
> My expectation on this test is that for each iteration a batchSize number
> of offer calls will be performed against a fresh new instance of ArrayDeque
> (the clean method is not needed).
> And to be sure it works as expected I will configure the benchmark to do
> GC.
> There is something I've missed?
>
> With great regards,
> Francesco
>
>
>
>


More information about the jmh-dev mailing list