Mercurial > hg > gc-bench
view src/main/java/org/openjdk/gcbench/roots/NewSync.java @ 87:f5ac05188aa1
Autogenerate class roots tests
author | shade |
---|---|
date | Wed, 22 Nov 2017 15:52:08 +0100 |
parents | src/main/java/org/openjdk/gcbench/roots/Synchronizers.java@7b87f91c5db9 |
children | 583fef4276f5 |
line wrap: on
line source
package org.openjdk.gcbench.roots; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Fork(1) @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MILLISECONDS) @Threads(Threads.MAX) @State(Scope.Benchmark) public class NewSync { SyncPair[] pairs; @Param({"100000"}) int size; @Setup public void setup() { pairs = new SyncPair[size]; for (int c = 0; c < size; c++) { pairs[c] = new SyncPair(); } } @TearDown(Level.Iteration) public void gc() { System.gc(); } @Benchmark public void test() throws InterruptedException { for (SyncPair pair : pairs) { pair.move(); } } static class SyncPair { int x, y; public synchronized void move() { x++; y--; } } }