JAVA-12387. Correct/Rename THREADS to TASKS and int threads to int tasks. (#13084)

This commit is contained in:
jsgrah-spring 2022-11-30 18:49:52 +01:00 committed by GitHub
parent 0e594f1a74
commit 21c42ebebc
2 changed files with 8 additions and 8 deletions

View File

@ -19,7 +19,7 @@ import org.openjdk.jmh.annotations.Warmup;
@Warmup(iterations = 0)
public class ConcurrentAccessBenchmark {
static final int SLOTS = 4;
static final int THREADS = 10000;
static final int TASKS = 10000;
static final int BUCKETS = Runtime.getRuntime().availableProcessors() * SLOTS;
SingleLock singleLock = new SingleLock();
StripedLock stripedLock = new StripedLock(BUCKETS);
@ -28,27 +28,27 @@ public class ConcurrentAccessBenchmark {
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public Map<String,String> singleLockHashMap() throws InterruptedException {
return singleLock.doWork(new HashMap<String,String>(), THREADS, SLOTS);
return singleLock.doWork(new HashMap<String,String>(), TASKS, SLOTS);
}
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public Map<String,String> stripedLockHashMap() throws InterruptedException {
return stripedLock.doWork(new HashMap<String,String>(), THREADS, SLOTS);
return stripedLock.doWork(new HashMap<String,String>(), TASKS, SLOTS);
}
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public Map<String,String> singleLockConcurrentHashMap() throws InterruptedException {
return singleLock.doWork(new ConcurrentHashMap<String,String>(), THREADS, SLOTS);
return singleLock.doWork(new ConcurrentHashMap<String,String>(), TASKS, SLOTS);
}
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public Map<String,String> stripedLockConcurrentHashMap() throws InterruptedException {
return stripedLock.doWork(new ConcurrentHashMap<String,String>(), THREADS, SLOTS);
return stripedLock.doWork(new ConcurrentHashMap<String,String>(), TASKS, SLOTS);
}
}

View File

@ -7,10 +7,10 @@ import com.google.common.base.Supplier;
public abstract class ConcurrentAccessExperiment {
public final Map<String,String> doWork(Map<String,String> map, int threads, int slots) {
CompletableFuture<?>[] requests = new CompletableFuture<?>[threads * slots];
public final Map<String,String> doWork(Map<String,String> map, int tasks, int slots) {
CompletableFuture<?>[] requests = new CompletableFuture<?>[tasks * slots];
for (int i = 0; i < threads; i++) {
for (int i = 0; i < tasks; i++) {
requests[slots * i + 0] = CompletableFuture.supplyAsync(putSupplier(map, i));
requests[slots * i + 1] = CompletableFuture.supplyAsync(getSupplier(map, i));
requests[slots * i + 2] = CompletableFuture.supplyAsync(getSupplier(map, i));