Adds JMH put/get throughput benchmarks (synchronizedMap vs ConcurrentHashMap, swept at 1/2/4/8 threads), a computeIfAbsent recursion trap demo (CHM tolerates recursion into a different key but throws IllegalStateException on the same key; plain HashMap throws ConcurrentModificationException even single-threaded), and a null-handling demo (CHM rejects null keys/values on put() and null keys on get() too). 7/7 JUnit tests pass; all output/ transcripts captured from real runs. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FhzLY5p6okFva3qsnsRyvM
92 lines
6.2 KiB
Plaintext
92 lines
6.2 KiB
Plaintext
$ java -jar benchmarks.jar PutGetBenchmark -t 2
|
|
|
|
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
|
|
WARNING: sun.misc.Unsafe::objectFieldOffset has been called by org.openjdk.jmh.util.Utils (file:/home/claude/java-core-examples/hashmap-concurrenthashmap/target/benchmarks.jar)
|
|
WARNING: Please consider reporting this to the maintainers of class org.openjdk.jmh.util.Utils
|
|
WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release
|
|
# JMH version: 1.37
|
|
# VM version: JDK 25.0.4.1, OpenJDK 64-Bit Server VM, 25.0.4.1+1-LTS
|
|
# VM invoker: /tmp/tools/jdk-25.0.4.1+1/bin/java
|
|
# VM options: -Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts -Djavax.net.ssl.trustStoreType=JKS -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=36265 -Dhttp.nonProxyHosts=localhost|127.0.0.1|::1|127.*|0.*|::|169.254.*|api.anthropic.com|api-staging.anthropic.com|api-pr-preview.anthropic.com|mcp-proxy.anthropic.com|mcp-proxy-staging.anthropic.com|registry.npmjs.org|jsr.io|npm.jsr.io|pypi.org|files.pythonhosted.org|index.crates.io|proxy.golang.org|host.docker.internal|10.*|172.16.*|172.17.*|172.18.*|172.19.*|172.20.*|172.21.*|172.22.*|172.23.*|172.24.*|172.25.*|172.26.*|172.27.*|172.28.*|172.29.*|172.30.*|172.31.*|192.168.*|100.64.0.0/10|*.svc.cluster.local|*.svc.cluster.local -Djdk.http.auth.tunneling.disabledSchemes= -Djdk.http.auth.proxying.disabledSchemes=
|
|
# Blackhole mode: compiler (auto-detected, use -Djmh.blackhole.autoDetect=false to disable)
|
|
# Warmup: 3 iterations, 1 s each
|
|
# Measurement: 5 iterations, 1 s each
|
|
# Timeout: 10 min per iteration
|
|
# Threads: 2 threads, will synchronize iterations
|
|
# Benchmark mode: Throughput, ops/time
|
|
# Benchmark: com.ankurm.hashmapconcurrenthashmap.PutGetBenchmark.concurrentHashMapPutGet
|
|
|
|
# Run progress: 0.00% complete, ETA 00:00:16
|
|
# Fork: 1 of 1
|
|
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
|
|
WARNING: sun.misc.Unsafe::objectFieldOffset has been called by org.openjdk.jmh.util.Utils (file:/home/claude/java-core-examples/hashmap-concurrenthashmap/target/benchmarks.jar)
|
|
WARNING: Please consider reporting this to the maintainers of class org.openjdk.jmh.util.Utils
|
|
WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release
|
|
# Warmup Iteration 1: 39233.654 ops/ms
|
|
# Warmup Iteration 2: 39452.589 ops/ms
|
|
# Warmup Iteration 3: 48184.915 ops/ms
|
|
Iteration 1: 47466.755 ops/ms
|
|
Iteration 2: 49016.648 ops/ms
|
|
Iteration 3: 45435.780 ops/ms
|
|
Iteration 4: 46289.315 ops/ms
|
|
Iteration 5: 48645.768 ops/ms
|
|
|
|
|
|
Result "com.ankurm.hashmapconcurrenthashmap.PutGetBenchmark.concurrentHashMapPutGet":
|
|
47370.853 ±(99.9%) 5858.003 ops/ms [Average]
|
|
(min, avg, max) = (45435.780, 47370.853, 49016.648), stdev = 1521.305
|
|
CI (99.9%): [41512.850, 53228.857] (assumes normal distribution)
|
|
|
|
|
|
# JMH version: 1.37
|
|
# VM version: JDK 25.0.4.1, OpenJDK 64-Bit Server VM, 25.0.4.1+1-LTS
|
|
# VM invoker: /tmp/tools/jdk-25.0.4.1+1/bin/java
|
|
# VM options: -Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts -Djavax.net.ssl.trustStoreType=JKS -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=36265 -Dhttp.nonProxyHosts=localhost|127.0.0.1|::1|127.*|0.*|::|169.254.*|api.anthropic.com|api-staging.anthropic.com|api-pr-preview.anthropic.com|mcp-proxy.anthropic.com|mcp-proxy-staging.anthropic.com|registry.npmjs.org|jsr.io|npm.jsr.io|pypi.org|files.pythonhosted.org|index.crates.io|proxy.golang.org|host.docker.internal|10.*|172.16.*|172.17.*|172.18.*|172.19.*|172.20.*|172.21.*|172.22.*|172.23.*|172.24.*|172.25.*|172.26.*|172.27.*|172.28.*|172.29.*|172.30.*|172.31.*|192.168.*|100.64.0.0/10|*.svc.cluster.local|*.svc.cluster.local -Djdk.http.auth.tunneling.disabledSchemes= -Djdk.http.auth.proxying.disabledSchemes=
|
|
# Blackhole mode: compiler (auto-detected, use -Djmh.blackhole.autoDetect=false to disable)
|
|
# Warmup: 3 iterations, 1 s each
|
|
# Measurement: 5 iterations, 1 s each
|
|
# Timeout: 10 min per iteration
|
|
# Threads: 2 threads, will synchronize iterations
|
|
# Benchmark mode: Throughput, ops/time
|
|
# Benchmark: com.ankurm.hashmapconcurrenthashmap.PutGetBenchmark.synchronizedHashMapPutGet
|
|
|
|
# Run progress: 50.00% complete, ETA 00:00:08
|
|
# Fork: 1 of 1
|
|
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
|
|
WARNING: sun.misc.Unsafe::objectFieldOffset has been called by org.openjdk.jmh.util.Utils (file:/home/claude/java-core-examples/hashmap-concurrenthashmap/target/benchmarks.jar)
|
|
WARNING: Please consider reporting this to the maintainers of class org.openjdk.jmh.util.Utils
|
|
WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release
|
|
# Warmup Iteration 1: 8475.811 ops/ms
|
|
# Warmup Iteration 2: 7944.591 ops/ms
|
|
# Warmup Iteration 3: 6576.291 ops/ms
|
|
Iteration 1: 8300.960 ops/ms
|
|
Iteration 2: 7385.743 ops/ms
|
|
Iteration 3: 6304.540 ops/ms
|
|
Iteration 4: 11817.370 ops/ms
|
|
Iteration 5: 7213.951 ops/ms
|
|
|
|
|
|
Result "com.ankurm.hashmapconcurrenthashmap.PutGetBenchmark.synchronizedHashMapPutGet":
|
|
8204.513 ±(99.9%) 8241.532 ops/ms [Average]
|
|
(min, avg, max) = (6304.540, 8204.513, 11817.370), stdev = 2140.300
|
|
CI (99.9%): [≈ 0, 16446.045] (assumes normal distribution)
|
|
|
|
|
|
# Run complete. Total time: 00:00:16
|
|
|
|
REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on
|
|
why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial
|
|
experiments, perform baseline and negative tests that provide experimental control, make sure
|
|
the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts.
|
|
Do not assume the numbers tell you what you want them to tell.
|
|
|
|
NOTE: Current JVM experimentally supports Compiler Blackholes, and they are in use. Please exercise
|
|
extra caution when trusting the results, look into the generated code to check the benchmark still
|
|
works, and factor in a small probability of new VM bugs. Additionally, while comparisons between
|
|
different JVMs are already problematic, the performance difference caused by different Blackhole
|
|
modes can be very significant. Please make sure you use the consistent Blackhole mode for comparisons.
|
|
|
|
Benchmark Mode Cnt Score Error Units
|
|
PutGetBenchmark.concurrentHashMapPutGet thrpt 5 47370.853 ± 5858.003 ops/ms
|
|
PutGetBenchmark.synchronizedHashMapPutGet thrpt 5 8204.513 ± 8241.532 ops/ms
|