diff --git a/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/util/ConcurrentMapBenchmark.java b/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/util/ConcurrentMapBenchmark.java index 776ca9b5816b9..7d7716cae2eca 100644 --- a/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/util/ConcurrentMapBenchmark.java +++ b/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/util/ConcurrentMapBenchmark.java @@ -189,4 +189,23 @@ public void testCopyOnWriteMapEntrySet(Blackhole blackhole) { } } } + + @Benchmark + @OperationsPerInvocation(TIMES) + public void testConcurrentHashMapComputeIfAbsentReadOnly(Blackhole blackhole) { + for (int i = 0; i < TIMES; i++) { + blackhole.consume(concurrentHashMap.computeIfAbsent( + ThreadLocalRandom.current().nextInt(0, mapSize), + newValue -> Integer.MAX_VALUE + )); + } + } + + @Benchmark + @OperationsPerInvocation(TIMES) + public void testConcurrentHashMapGetReadOnly(Blackhole blackhole) { + for (int i = 0; i < TIMES; i++) { + blackhole.consume(concurrentHashMap.get(ThreadLocalRandom.current().nextInt(0, mapSize))); + } + } }