parallel-streams: JMH benchmarks and demos for when parallel streams are slower
N x Q model, source splittability, boxing, ordered operations, common-pool starvation, and parallel-stream correctness bugs. Captured output in output/. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6hCTuFrQT8xKmmMrF
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
# parallel-streams
|
||||
|
||||
Companion code for the ankurm.com post *"Java Parallel Streams: When They're Slower (JMH Benchmarks and the Common Pool)."*
|
||||
Module in `java-core-examples`, the Java-core series. There is deliberately no `docs/` folder: the
|
||||
deeper material lives in collapsible sections inside the post itself.
|
||||
|
||||
## Versions this was built and tested against
|
||||
|
||||
| Component | Version | Notes |
|
||||
|---|---|---|
|
||||
| JDK | 25.0.5+8 (Temurin, LTS) | |
|
||||
| JMH | 1.37 | Latest GA on Maven Central; released 3 Aug 2023. |
|
||||
| JUnit Jupiter | 5.11.0 | |
|
||||
| Maven | 3.9.11 | |
|
||||
| Host | 2 vCPU shared sandbox | Default common-pool parallelism is therefore 1 (see `output/00`). Speed-ups cap near 2x. Read the shape of the numbers, not the third significant digit. |
|
||||
|
||||
## Quickstart
|
||||
|
||||
```bash
|
||||
export JAVA_HOME=/path/to/jdk-25
|
||||
mvn -q package # builds target/benchmarks.jar and runs the tests
|
||||
java -Djava.util.concurrent.ForkJoinPool.common.parallelism=3 \
|
||||
-cp target/classes com.ankurm.parallelstreams.CorrectnessBugsDemo
|
||||
java -Djava.util.concurrent.ForkJoinPool.common.parallelism=3 \
|
||||
-cp target/classes com.ankurm.parallelstreams.CommonPoolStarvationDemo
|
||||
java -jar target/benchmarks.jar NqBenchmark -f 1 -wi 3 -w 1s -i 5 -r 1s
|
||||
```
|
||||
|
||||
`scripts/run-all.sh` regenerates every file in `output/` (about 6 minutes on 2 vCPUs).
|
||||
`scripts/run.sh <ClassName>` runs one demo class ad hoc.
|
||||
|
||||
## What's in here
|
||||
|
||||
| File | What it shows |
|
||||
|---|---|
|
||||
| `NqBenchmark.java` | N elements x Q units of CPU per element, sequential vs parallel, at three sizes and two costs. Where parallel starts to pay. |
|
||||
| `SourceBenchmark.java` | The same work over `int[]`, `ArrayList`, `LinkedList` and `Stream.iterate`: how splittable the source is decides the outcome. |
|
||||
| `BoxingBenchmark.java` | A cheap sum over 1,000,000 elements, primitive vs boxed, with `-prof gc` allocation per call. |
|
||||
| `OrderedOpsBenchmark.java` | `limit` and `distinct`, ordered vs `unordered()`, against a sequential baseline. |
|
||||
| `CommonPoolStarvationDemo.java` | A neighbour that blocks the common pool slows an unrelated parallel stream 4x; a private `ForkJoinPool` and virtual threads as the fixes. |
|
||||
| `CorrectnessBugsDemo.java` | `forEach(list::add)`, a non-identity `reduce` identity, a non-associative accumulator, and a racy counter. |
|
||||
| `ParallelStreamsTest.java` | Pins the deterministic claims. No timing assertions. |
|
||||
| `output/00-07` | Captured runs of all of the above. |
|
||||
|
||||
## Notes worth knowing before reading the post
|
||||
|
||||
- **JMH settings are light** (`-f 1 -wi 3 -i 5`, one second each) to keep the whole capture to minutes. Error bars are reported in the output; the post draws conclusions only from differences clearly larger than them.
|
||||
- **The demos pin `common.parallelism=3`** so they behave the same on any machine. The JMH runs do not: they use the default for the host, which is 1 on 2 CPUs.
|
||||
- **`BoxingBenchmark`'s first draft compared two different stream sources** (`Stream.iterate` for the sequential boxed case, `range().boxed()` for the parallel one). That is not a fair pair; both now use `IntStream.range(..).boxed()`.
|
||||
|
||||
## License
|
||||
|
||||
MIT - see the [repo-wide LICENSE](../LICENSE).
|
||||
@@ -0,0 +1,4 @@
|
||||
availableProcessors = 2 (default commonPool parallelism = 1)
|
||||
openjdk version "25.0.5" 2026-10-20 LTS
|
||||
OpenJDK Runtime Environment Temurin-25.0.5+8 (build 25.0.5+8-LTS)
|
||||
OpenJDK 64-Bit Server VM Temurin-25.0.5+8 (build 25.0.5+8-LTS, mixed mode, sharing)
|
||||
@@ -0,0 +1,15 @@
|
||||
1. forEach(list::add), n = 100000, ten runs (-1 = exception):
|
||||
sizes: 90126 86309 22551 86194 -1 22732 87868 10443 15012 77596
|
||||
collect(toList()) size: 100000
|
||||
|
||||
2. reduce(10, Integer::sum) over 1..100
|
||||
sequential: 5060
|
||||
parallel : 5210
|
||||
|
||||
3. reduce(0, (a, b) -> a - b) over 1..1000
|
||||
sequential: -500500
|
||||
parallel : 0
|
||||
|
||||
4. counter[0]++ in forEach, n = 100000
|
||||
racy : 99997
|
||||
atomic : 100000
|
||||
@@ -0,0 +1,15 @@
|
||||
availableProcessors = 2
|
||||
commonPool parallelism = 3
|
||||
|
||||
1. Victim alone
|
||||
victim took 201 ms
|
||||
|
||||
2. Victim while a neighbour BLOCKS the common pool (8 tasks x 2000 ms)
|
||||
victim took 803 ms
|
||||
|
||||
3. Same neighbour, but it runs in its OWN ForkJoinPool(3)
|
||||
victim took 200 ms
|
||||
|
||||
4. 20 blocking tasks x 200 ms: parallel stream vs virtual threads
|
||||
parallel stream : 1002 ms
|
||||
virtual threads : 216 ms
|
||||
@@ -0,0 +1,399 @@
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.NqBenchmark.parallel
|
||||
# Parameters: (n = 100, q = 1)
|
||||
|
||||
# Run progress: 0.00% complete, ETA 00:01:36
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 2.554 us/op
|
||||
# Warmup Iteration 2: 2.826 us/op
|
||||
# Warmup Iteration 3: 3.246 us/op
|
||||
Iteration 1: 3.302 us/op
|
||||
Iteration 2: 3.168 us/op
|
||||
Iteration 3: 3.191 us/op
|
||||
Iteration 4: 3.197 us/op
|
||||
Iteration 5: 3.276 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.NqBenchmark.parallel":
|
||||
3.227 ±(99.9%) 0.227 us/op [Average]
|
||||
(min, avg, max) = (3.168, 3.227, 3.302), stdev = 0.059
|
||||
CI (99.9%): [3.000, 3.453] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.NqBenchmark.parallel
|
||||
# Parameters: (n = 100, q = 100)
|
||||
|
||||
# Run progress: 8.33% complete, ETA 00:01:30
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 17.115 us/op
|
||||
# Warmup Iteration 2: 19.112 us/op
|
||||
# Warmup Iteration 3: 17.243 us/op
|
||||
Iteration 1: 17.042 us/op
|
||||
Iteration 2: 18.133 us/op
|
||||
Iteration 3: 18.558 us/op
|
||||
Iteration 4: 16.680 us/op
|
||||
Iteration 5: 14.709 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.NqBenchmark.parallel":
|
||||
17.024 ±(99.9%) 5.796 us/op [Average]
|
||||
(min, avg, max) = (14.709, 17.024, 18.558), stdev = 1.505
|
||||
CI (99.9%): [11.228, 22.821] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.NqBenchmark.parallel
|
||||
# Parameters: (n = 10000, q = 1)
|
||||
|
||||
# Run progress: 16.67% complete, ETA 00:01:22
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 41.559 us/op
|
||||
# Warmup Iteration 2: 41.886 us/op
|
||||
# Warmup Iteration 3: 40.756 us/op
|
||||
Iteration 1: 45.860 us/op
|
||||
Iteration 2: 45.214 us/op
|
||||
Iteration 3: 45.519 us/op
|
||||
Iteration 4: 45.168 us/op
|
||||
Iteration 5: 44.723 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.NqBenchmark.parallel":
|
||||
45.297 ±(99.9%) 1.633 us/op [Average]
|
||||
(min, avg, max) = (44.723, 45.297, 45.860), stdev = 0.424
|
||||
CI (99.9%): [43.664, 46.929] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.NqBenchmark.parallel
|
||||
# Parameters: (n = 10000, q = 100)
|
||||
|
||||
# Run progress: 25.00% complete, ETA 00:01:14
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 818.776 us/op
|
||||
# Warmup Iteration 2: 723.115 us/op
|
||||
# Warmup Iteration 3: 683.672 us/op
|
||||
Iteration 1: 695.548 us/op
|
||||
Iteration 2: 677.217 us/op
|
||||
Iteration 3: 702.129 us/op
|
||||
Iteration 4: 691.356 us/op
|
||||
Iteration 5: 678.731 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.NqBenchmark.parallel":
|
||||
688.996 ±(99.9%) 41.521 us/op [Average]
|
||||
(min, avg, max) = (677.217, 688.996, 702.129), stdev = 10.783
|
||||
CI (99.9%): [647.475, 730.518] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.NqBenchmark.parallel
|
||||
# Parameters: (n = 1000000, q = 1)
|
||||
|
||||
# Run progress: 33.33% complete, ETA 00:01:06
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 2051.571 us/op
|
||||
# Warmup Iteration 2: 1906.834 us/op
|
||||
# Warmup Iteration 3: 2024.894 us/op
|
||||
Iteration 1: 1801.248 us/op
|
||||
Iteration 2: 1801.422 us/op
|
||||
Iteration 3: 1950.267 us/op
|
||||
Iteration 4: 2295.446 us/op
|
||||
Iteration 5: 1913.766 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.NqBenchmark.parallel":
|
||||
1952.430 ±(99.9%) 781.640 us/op [Average]
|
||||
(min, avg, max) = (1801.248, 1952.430, 2295.446), stdev = 202.989
|
||||
CI (99.9%): [1170.790, 2734.070] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.NqBenchmark.parallel
|
||||
# Parameters: (n = 1000000, q = 100)
|
||||
|
||||
# Run progress: 41.67% complete, ETA 00:00:57
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 67554.950 us/op
|
||||
# Warmup Iteration 2: 63880.972 us/op
|
||||
# Warmup Iteration 3: 67555.514 us/op
|
||||
Iteration 1: 66500.964 us/op
|
||||
Iteration 2: 66413.244 us/op
|
||||
Iteration 3: 65635.051 us/op
|
||||
Iteration 4: 68084.734 us/op
|
||||
Iteration 5: 64267.643 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.NqBenchmark.parallel":
|
||||
66180.327 ±(99.9%) 5356.241 us/op [Average]
|
||||
(min, avg, max) = (64267.643, 66180.327, 68084.734), stdev = 1390.999
|
||||
CI (99.9%): [60824.086, 71536.569] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.NqBenchmark.sequential
|
||||
# Parameters: (n = 100, q = 1)
|
||||
|
||||
# Run progress: 50.00% complete, ETA 00:00:49
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 0.385 us/op
|
||||
# Warmup Iteration 2: 0.359 us/op
|
||||
# Warmup Iteration 3: 0.337 us/op
|
||||
Iteration 1: 0.338 us/op
|
||||
Iteration 2: 0.343 us/op
|
||||
Iteration 3: 0.352 us/op
|
||||
Iteration 4: 0.346 us/op
|
||||
Iteration 5: 0.344 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.NqBenchmark.sequential":
|
||||
0.345 ±(99.9%) 0.020 us/op [Average]
|
||||
(min, avg, max) = (0.338, 0.345, 0.352), stdev = 0.005
|
||||
CI (99.9%): [0.324, 0.365] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.NqBenchmark.sequential
|
||||
# Parameters: (n = 100, q = 100)
|
||||
|
||||
# Run progress: 58.33% complete, ETA 00:00:41
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 13.752 us/op
|
||||
# Warmup Iteration 2: 13.339 us/op
|
||||
# Warmup Iteration 3: 13.433 us/op
|
||||
Iteration 1: 13.190 us/op
|
||||
Iteration 2: 12.791 us/op
|
||||
Iteration 3: 12.906 us/op
|
||||
Iteration 4: 12.862 us/op
|
||||
Iteration 5: 13.182 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.NqBenchmark.sequential":
|
||||
12.986 ±(99.9%) 0.719 us/op [Average]
|
||||
(min, avg, max) = (12.791, 12.986, 13.190), stdev = 0.187
|
||||
CI (99.9%): [12.267, 13.705] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.NqBenchmark.sequential
|
||||
# Parameters: (n = 10000, q = 1)
|
||||
|
||||
# Run progress: 66.67% complete, ETA 00:00:33
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 33.847 us/op
|
||||
# Warmup Iteration 2: 34.601 us/op
|
||||
# Warmup Iteration 3: 32.702 us/op
|
||||
Iteration 1: 31.444 us/op
|
||||
Iteration 2: 31.912 us/op
|
||||
Iteration 3: 31.441 us/op
|
||||
Iteration 4: 36.858 us/op
|
||||
Iteration 5: 33.124 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.NqBenchmark.sequential":
|
||||
32.956 ±(99.9%) 8.808 us/op [Average]
|
||||
(min, avg, max) = (31.441, 32.956, 36.858), stdev = 2.287
|
||||
CI (99.9%): [24.147, 41.764] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.NqBenchmark.sequential
|
||||
# Parameters: (n = 10000, q = 100)
|
||||
|
||||
# Run progress: 75.00% complete, ETA 00:00:24
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 1323.332 us/op
|
||||
# Warmup Iteration 2: 1291.482 us/op
|
||||
# Warmup Iteration 3: 1267.897 us/op
|
||||
Iteration 1: 1298.120 us/op
|
||||
Iteration 2: 1318.923 us/op
|
||||
Iteration 3: 1306.951 us/op
|
||||
Iteration 4: 1287.234 us/op
|
||||
Iteration 5: 1314.010 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.NqBenchmark.sequential":
|
||||
1305.048 ±(99.9%) 48.775 us/op [Average]
|
||||
(min, avg, max) = (1287.234, 1305.048, 1318.923), stdev = 12.667
|
||||
CI (99.9%): [1256.273, 1353.823] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.NqBenchmark.sequential
|
||||
# Parameters: (n = 1000000, q = 1)
|
||||
|
||||
# Run progress: 83.33% complete, ETA 00:00:16
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 3185.234 us/op
|
||||
# Warmup Iteration 2: 3270.377 us/op
|
||||
# Warmup Iteration 3: 3403.997 us/op
|
||||
Iteration 1: 3126.314 us/op
|
||||
Iteration 2: 3046.140 us/op
|
||||
Iteration 3: 3579.626 us/op
|
||||
Iteration 4: 3076.687 us/op
|
||||
Iteration 5: 3034.810 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.NqBenchmark.sequential":
|
||||
3172.715 ±(99.9%) 886.464 us/op [Average]
|
||||
(min, avg, max) = (3034.810, 3172.715, 3579.626), stdev = 230.212
|
||||
CI (99.9%): [2286.252, 4059.179] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.NqBenchmark.sequential
|
||||
# Parameters: (n = 1000000, q = 100)
|
||||
|
||||
# Run progress: 91.67% complete, ETA 00:00:08
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 125134.566 us/op
|
||||
# Warmup Iteration 2: 121151.145 us/op
|
||||
# Warmup Iteration 3: 126327.662 us/op
|
||||
Iteration 1: 127210.986 us/op
|
||||
Iteration 2: 127633.563 us/op
|
||||
Iteration 3: 126364.109 us/op
|
||||
Iteration 4: 131880.637 us/op
|
||||
Iteration 5: 124313.179 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.NqBenchmark.sequential":
|
||||
127480.495 ±(99.9%) 10673.912 us/op [Average]
|
||||
(min, avg, max) = (124313.179, 127480.495, 131880.637), stdev = 2771.981
|
||||
CI (99.9%): [116806.582, 138154.407] (assumes normal distribution)
|
||||
|
||||
|
||||
# Run complete. Total time: 00:01:39
|
||||
|
||||
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 (n) (q) Mode Cnt Score Error Units
|
||||
NqBenchmark.parallel 100 1 avgt 5 3.227 ± 0.227 us/op
|
||||
NqBenchmark.parallel 100 100 avgt 5 17.024 ± 5.796 us/op
|
||||
NqBenchmark.parallel 10000 1 avgt 5 45.297 ± 1.633 us/op
|
||||
NqBenchmark.parallel 10000 100 avgt 5 688.996 ± 41.521 us/op
|
||||
NqBenchmark.parallel 1000000 1 avgt 5 1952.430 ± 781.640 us/op
|
||||
NqBenchmark.parallel 1000000 100 avgt 5 66180.327 ± 5356.241 us/op
|
||||
NqBenchmark.sequential 100 1 avgt 5 0.345 ± 0.020 us/op
|
||||
NqBenchmark.sequential 100 100 avgt 5 12.986 ± 0.719 us/op
|
||||
NqBenchmark.sequential 10000 1 avgt 5 32.956 ± 8.808 us/op
|
||||
NqBenchmark.sequential 10000 100 avgt 5 1305.048 ± 48.775 us/op
|
||||
NqBenchmark.sequential 1000000 1 avgt 5 3172.715 ± 886.464 us/op
|
||||
NqBenchmark.sequential 1000000 100 avgt 5 127480.495 ± 10673.912 us/op
|
||||
@@ -0,0 +1,263 @@
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.SourceBenchmark.arrayList_par
|
||||
|
||||
# Run progress: 0.00% complete, ETA 00:01:04
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 875.141 us/op
|
||||
# Warmup Iteration 2: 1000.046 us/op
|
||||
# Warmup Iteration 3: 887.776 us/op
|
||||
Iteration 1: 892.010 us/op
|
||||
Iteration 2: 897.553 us/op
|
||||
Iteration 3: 799.533 us/op
|
||||
Iteration 4: 810.756 us/op
|
||||
Iteration 5: 923.902 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.SourceBenchmark.arrayList_par":
|
||||
864.751 ±(99.9%) 215.142 us/op [Average]
|
||||
(min, avg, max) = (799.533, 864.751, 923.902), stdev = 55.872
|
||||
CI (99.9%): [649.608, 1079.893] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.SourceBenchmark.arrayList_seq
|
||||
|
||||
# Run progress: 12.50% complete, ETA 00:00:57
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 1707.637 us/op
|
||||
# Warmup Iteration 2: 1671.232 us/op
|
||||
# Warmup Iteration 3: 1639.488 us/op
|
||||
Iteration 1: 1646.433 us/op
|
||||
Iteration 2: 1587.087 us/op
|
||||
Iteration 3: 1617.898 us/op
|
||||
Iteration 4: 1563.128 us/op
|
||||
Iteration 5: 1565.962 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.SourceBenchmark.arrayList_seq":
|
||||
1596.102 ±(99.9%) 137.297 us/op [Average]
|
||||
(min, avg, max) = (1563.128, 1596.102, 1646.433), stdev = 35.656
|
||||
CI (99.9%): [1458.805, 1733.399] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.SourceBenchmark.intArray_par
|
||||
|
||||
# Run progress: 25.00% complete, ETA 00:00:49
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 844.636 us/op
|
||||
# Warmup Iteration 2: 812.772 us/op
|
||||
# Warmup Iteration 3: 799.070 us/op
|
||||
Iteration 1: 934.718 us/op
|
||||
Iteration 2: 807.934 us/op
|
||||
Iteration 3: 833.626 us/op
|
||||
Iteration 4: 805.721 us/op
|
||||
Iteration 5: 808.579 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.SourceBenchmark.intArray_par":
|
||||
838.116 ±(99.9%) 212.527 us/op [Average]
|
||||
(min, avg, max) = (805.721, 838.116, 934.718), stdev = 55.192
|
||||
CI (99.9%): [625.589, 1050.642] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.SourceBenchmark.intArray_seq
|
||||
|
||||
# Run progress: 37.50% complete, ETA 00:00:41
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 1557.406 us/op
|
||||
# Warmup Iteration 2: 1627.566 us/op
|
||||
# Warmup Iteration 3: 1530.733 us/op
|
||||
Iteration 1: 1672.832 us/op
|
||||
Iteration 2: 1485.387 us/op
|
||||
Iteration 3: 1511.766 us/op
|
||||
Iteration 4: 1480.313 us/op
|
||||
Iteration 5: 1506.690 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.SourceBenchmark.intArray_seq":
|
||||
1531.397 ±(99.9%) 308.809 us/op [Average]
|
||||
(min, avg, max) = (1480.313, 1531.397, 1672.832), stdev = 80.197
|
||||
CI (99.9%): [1222.588, 1840.206] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.SourceBenchmark.iterate_par
|
||||
|
||||
# Run progress: 50.00% complete, ETA 00:00:32
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 3539.271 us/op
|
||||
# Warmup Iteration 2: 3281.146 us/op
|
||||
# Warmup Iteration 3: 2699.139 us/op
|
||||
Iteration 1: 2826.627 us/op
|
||||
Iteration 2: 2769.716 us/op
|
||||
Iteration 3: 2790.944 us/op
|
||||
Iteration 4: 2817.520 us/op
|
||||
Iteration 5: 2756.321 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.SourceBenchmark.iterate_par":
|
||||
2792.226 ±(99.9%) 115.852 us/op [Average]
|
||||
(min, avg, max) = (2756.321, 2792.226, 2826.627), stdev = 30.086
|
||||
CI (99.9%): [2676.374, 2908.078] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.SourceBenchmark.iterate_seq
|
||||
|
||||
# Run progress: 62.50% complete, ETA 00:00:24
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 2122.584 us/op
|
||||
# Warmup Iteration 2: 2051.970 us/op
|
||||
# Warmup Iteration 3: 1984.262 us/op
|
||||
Iteration 1: 1958.438 us/op
|
||||
Iteration 2: 1903.397 us/op
|
||||
Iteration 3: 1902.650 us/op
|
||||
Iteration 4: 2086.336 us/op
|
||||
Iteration 5: 1962.841 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.SourceBenchmark.iterate_seq":
|
||||
1962.732 ±(99.9%) 288.329 us/op [Average]
|
||||
(min, avg, max) = (1902.650, 1962.732, 2086.336), stdev = 74.878
|
||||
CI (99.9%): [1674.404, 2251.061] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.SourceBenchmark.linkedList_par
|
||||
|
||||
# Run progress: 75.00% complete, ETA 00:00:16
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 1723.307 us/op
|
||||
# Warmup Iteration 2: 1523.676 us/op
|
||||
# Warmup Iteration 3: 1797.511 us/op
|
||||
Iteration 1: 1736.234 us/op
|
||||
Iteration 2: 1713.686 us/op
|
||||
Iteration 3: 1867.840 us/op
|
||||
Iteration 4: 1627.651 us/op
|
||||
Iteration 5: 1840.748 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.SourceBenchmark.linkedList_par":
|
||||
1757.232 ±(99.9%) 376.977 us/op [Average]
|
||||
(min, avg, max) = (1627.651, 1757.232, 1867.840), stdev = 97.900
|
||||
CI (99.9%): [1380.255, 2134.208] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.SourceBenchmark.linkedList_seq
|
||||
|
||||
# Run progress: 87.50% complete, ETA 00:00:08
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 1624.775 us/op
|
||||
# Warmup Iteration 2: 1606.300 us/op
|
||||
# Warmup Iteration 3: 1722.162 us/op
|
||||
Iteration 1: 1703.266 us/op
|
||||
Iteration 2: 1687.384 us/op
|
||||
Iteration 3: 1581.179 us/op
|
||||
Iteration 4: 1695.401 us/op
|
||||
Iteration 5: 1660.109 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.SourceBenchmark.linkedList_seq":
|
||||
1665.468 ±(99.9%) 191.938 us/op [Average]
|
||||
(min, avg, max) = (1581.179, 1665.468, 1703.266), stdev = 49.846
|
||||
CI (99.9%): [1473.530, 1857.405] (assumes normal distribution)
|
||||
|
||||
|
||||
# Run complete. Total time: 00:01:05
|
||||
|
||||
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
|
||||
SourceBenchmark.arrayList_par avgt 5 864.751 ± 215.142 us/op
|
||||
SourceBenchmark.arrayList_seq avgt 5 1596.102 ± 137.297 us/op
|
||||
SourceBenchmark.intArray_par avgt 5 838.116 ± 212.527 us/op
|
||||
SourceBenchmark.intArray_seq avgt 5 1531.397 ± 308.809 us/op
|
||||
SourceBenchmark.iterate_par avgt 5 2792.226 ± 115.852 us/op
|
||||
SourceBenchmark.iterate_seq avgt 5 1962.732 ± 288.329 us/op
|
||||
SourceBenchmark.linkedList_par avgt 5 1757.232 ± 376.977 us/op
|
||||
SourceBenchmark.linkedList_seq avgt 5 1665.468 ± 191.938 us/op
|
||||
@@ -0,0 +1,283 @@
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.BoxingBenchmark.boxed_par
|
||||
|
||||
# Run progress: 0.00% complete, ETA 00:00:32
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 974.986 us/op
|
||||
# Warmup Iteration 2: 848.792 us/op
|
||||
# Warmup Iteration 3: 796.211 us/op
|
||||
Iteration 1: 870.351 us/op
|
||||
gc.alloc.rate: 1.213 MB/sec
|
||||
gc.alloc.rate.norm: 1107.770 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 2: 824.111 us/op
|
||||
gc.alloc.rate: 1.281 MB/sec
|
||||
gc.alloc.rate.norm: 1108.642 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 3: 845.852 us/op
|
||||
gc.alloc.rate: 1.243 MB/sec
|
||||
gc.alloc.rate.norm: 1107.741 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 4: 861.177 us/op
|
||||
gc.alloc.rate: 1.227 MB/sec
|
||||
gc.alloc.rate.norm: 1109.962 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 5: 886.850 us/op
|
||||
gc.alloc.rate: 1.190 MB/sec
|
||||
gc.alloc.rate.norm: 1106.539 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.BoxingBenchmark.boxed_par":
|
||||
857.668 ±(99.9%) 92.144 us/op [Average]
|
||||
(min, avg, max) = (824.111, 857.668, 886.850), stdev = 23.930
|
||||
CI (99.9%): [765.524, 949.812] (assumes normal distribution)
|
||||
|
||||
Secondary result "com.ankurm.parallelstreams.BoxingBenchmark.boxed_par:gc.alloc.rate":
|
||||
1.231 ±(99.9%) 0.132 MB/sec [Average]
|
||||
(min, avg, max) = (1.190, 1.231, 1.281), stdev = 0.034
|
||||
CI (99.9%): [1.099, 1.362] (assumes normal distribution)
|
||||
|
||||
Secondary result "com.ankurm.parallelstreams.BoxingBenchmark.boxed_par:gc.alloc.rate.norm":
|
||||
1108.131 ±(99.9%) 4.882 B/op [Average]
|
||||
(min, avg, max) = (1106.539, 1108.131, 1109.962), stdev = 1.268
|
||||
CI (99.9%): [1103.249, 1113.013] (assumes normal distribution)
|
||||
|
||||
Secondary result "com.ankurm.parallelstreams.BoxingBenchmark.boxed_par:gc.count":
|
||||
≈ 0 counts
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.BoxingBenchmark.boxed_seq
|
||||
|
||||
# Run progress: 25.00% complete, ETA 00:00:24
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 1431.858 us/op
|
||||
# Warmup Iteration 2: 1497.100 us/op
|
||||
# Warmup Iteration 3: 1432.571 us/op
|
||||
Iteration 1: 1389.004 us/op
|
||||
gc.alloc.rate: 0.232 MB/sec
|
||||
gc.alloc.rate.norm: 337.709 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 2: 1421.737 us/op
|
||||
gc.alloc.rate: 0.227 MB/sec
|
||||
gc.alloc.rate.norm: 337.943 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 3: 1439.071 us/op
|
||||
gc.alloc.rate: 0.224 MB/sec
|
||||
gc.alloc.rate.norm: 338.029 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 4: 1446.336 us/op
|
||||
gc.alloc.rate: 0.223 MB/sec
|
||||
gc.alloc.rate.norm: 338.116 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 5: 1482.209 us/op
|
||||
gc.alloc.rate: 0.218 MB/sec
|
||||
gc.alloc.rate.norm: 338.584 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.BoxingBenchmark.boxed_seq":
|
||||
1435.671 ±(99.9%) 131.474 us/op [Average]
|
||||
(min, avg, max) = (1389.004, 1435.671, 1482.209), stdev = 34.143
|
||||
CI (99.9%): [1304.197, 1567.146] (assumes normal distribution)
|
||||
|
||||
Secondary result "com.ankurm.parallelstreams.BoxingBenchmark.boxed_seq:gc.alloc.rate":
|
||||
0.224 ±(99.9%) 0.020 MB/sec [Average]
|
||||
(min, avg, max) = (0.218, 0.224, 0.232), stdev = 0.005
|
||||
CI (99.9%): [0.205, 0.244] (assumes normal distribution)
|
||||
|
||||
Secondary result "com.ankurm.parallelstreams.BoxingBenchmark.boxed_seq:gc.alloc.rate.norm":
|
||||
338.076 ±(99.9%) 1.239 B/op [Average]
|
||||
(min, avg, max) = (337.709, 338.076, 338.584), stdev = 0.322
|
||||
CI (99.9%): [336.837, 339.315] (assumes normal distribution)
|
||||
|
||||
Secondary result "com.ankurm.parallelstreams.BoxingBenchmark.boxed_seq:gc.count":
|
||||
≈ 0 counts
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.BoxingBenchmark.primitive_par
|
||||
|
||||
# Run progress: 50.00% complete, ETA 00:00:16
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 205.937 us/op
|
||||
# Warmup Iteration 2: 170.623 us/op
|
||||
# Warmup Iteration 3: 162.141 us/op
|
||||
Iteration 1: 161.161 us/op
|
||||
gc.alloc.rate: 5.462 MB/sec
|
||||
gc.alloc.rate.norm: 923.506 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 2: 164.425 us/op
|
||||
gc.alloc.rate: 5.369 MB/sec
|
||||
gc.alloc.rate.norm: 925.919 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 3: 166.830 us/op
|
||||
gc.alloc.rate: 5.271 MB/sec
|
||||
gc.alloc.rate.norm: 922.734 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 4: 155.618 us/op
|
||||
gc.alloc.rate: 5.651 MB/sec
|
||||
gc.alloc.rate.norm: 922.257 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 5: 153.176 us/op
|
||||
gc.alloc.rate: 5.726 MB/sec
|
||||
gc.alloc.rate.norm: 919.993 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.BoxingBenchmark.primitive_par":
|
||||
160.242 ±(99.9%) 22.209 us/op [Average]
|
||||
(min, avg, max) = (153.176, 160.242, 166.830), stdev = 5.768
|
||||
CI (99.9%): [138.033, 182.451] (assumes normal distribution)
|
||||
|
||||
Secondary result "com.ankurm.parallelstreams.BoxingBenchmark.primitive_par:gc.alloc.rate":
|
||||
5.496 ±(99.9%) 0.733 MB/sec [Average]
|
||||
(min, avg, max) = (5.271, 5.496, 5.726), stdev = 0.190
|
||||
CI (99.9%): [4.763, 6.229] (assumes normal distribution)
|
||||
|
||||
Secondary result "com.ankurm.parallelstreams.BoxingBenchmark.primitive_par:gc.alloc.rate.norm":
|
||||
922.882 ±(99.9%) 8.253 B/op [Average]
|
||||
(min, avg, max) = (919.993, 922.882, 925.919), stdev = 2.143
|
||||
CI (99.9%): [914.629, 931.135] (assumes normal distribution)
|
||||
|
||||
Secondary result "com.ankurm.parallelstreams.BoxingBenchmark.primitive_par:gc.count":
|
||||
≈ 0 counts
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.BoxingBenchmark.primitive_seq
|
||||
|
||||
# Run progress: 75.00% complete, ETA 00:00:08
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 273.688 us/op
|
||||
# Warmup Iteration 2: 265.275 us/op
|
||||
# Warmup Iteration 3: 264.934 us/op
|
||||
Iteration 1: 274.675 us/op
|
||||
gc.alloc.rate: 0.645 MB/sec
|
||||
gc.alloc.rate.norm: 185.921 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 2: 271.925 us/op
|
||||
gc.alloc.rate: 0.651 MB/sec
|
||||
gc.alloc.rate.norm: 185.902 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 3: 269.727 us/op
|
||||
gc.alloc.rate: 0.655 MB/sec
|
||||
gc.alloc.rate.norm: 185.887 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 4: 266.509 us/op
|
||||
gc.alloc.rate: 0.665 MB/sec
|
||||
gc.alloc.rate.norm: 185.865 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
Iteration 5: 265.184 us/op
|
||||
gc.alloc.rate: 0.668 MB/sec
|
||||
gc.alloc.rate.norm: 185.847 B/op
|
||||
gc.count: ≈ 0 counts
|
||||
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.BoxingBenchmark.primitive_seq":
|
||||
269.604 ±(99.9%) 14.943 us/op [Average]
|
||||
(min, avg, max) = (265.184, 269.604, 274.675), stdev = 3.881
|
||||
CI (99.9%): [254.660, 284.547] (assumes normal distribution)
|
||||
|
||||
Secondary result "com.ankurm.parallelstreams.BoxingBenchmark.primitive_seq:gc.alloc.rate":
|
||||
0.657 ±(99.9%) 0.036 MB/sec [Average]
|
||||
(min, avg, max) = (0.645, 0.657, 0.668), stdev = 0.009
|
||||
CI (99.9%): [0.621, 0.693] (assumes normal distribution)
|
||||
|
||||
Secondary result "com.ankurm.parallelstreams.BoxingBenchmark.primitive_seq:gc.alloc.rate.norm":
|
||||
185.884 ±(99.9%) 0.113 B/op [Average]
|
||||
(min, avg, max) = (185.847, 185.884, 185.921), stdev = 0.029
|
||||
CI (99.9%): [185.771, 185.997] (assumes normal distribution)
|
||||
|
||||
Secondary result "com.ankurm.parallelstreams.BoxingBenchmark.primitive_seq:gc.count":
|
||||
≈ 0 counts
|
||||
|
||||
|
||||
# Run complete. Total time: 00:00:33
|
||||
|
||||
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
|
||||
BoxingBenchmark.boxed_par avgt 5 857.668 ± 92.144 us/op
|
||||
BoxingBenchmark.boxed_par:gc.alloc.rate avgt 5 1.231 ± 0.132 MB/sec
|
||||
BoxingBenchmark.boxed_par:gc.alloc.rate.norm avgt 5 1108.131 ± 4.882 B/op
|
||||
BoxingBenchmark.boxed_par:gc.count avgt 5 ≈ 0 counts
|
||||
BoxingBenchmark.boxed_seq avgt 5 1435.671 ± 131.474 us/op
|
||||
BoxingBenchmark.boxed_seq:gc.alloc.rate avgt 5 0.224 ± 0.020 MB/sec
|
||||
BoxingBenchmark.boxed_seq:gc.alloc.rate.norm avgt 5 338.076 ± 1.239 B/op
|
||||
BoxingBenchmark.boxed_seq:gc.count avgt 5 ≈ 0 counts
|
||||
BoxingBenchmark.primitive_par avgt 5 160.242 ± 22.209 us/op
|
||||
BoxingBenchmark.primitive_par:gc.alloc.rate avgt 5 5.496 ± 0.733 MB/sec
|
||||
BoxingBenchmark.primitive_par:gc.alloc.rate.norm avgt 5 922.882 ± 8.253 B/op
|
||||
BoxingBenchmark.primitive_par:gc.count avgt 5 ≈ 0 counts
|
||||
BoxingBenchmark.primitive_seq avgt 5 269.604 ± 14.943 us/op
|
||||
BoxingBenchmark.primitive_seq:gc.alloc.rate avgt 5 0.657 ± 0.036 MB/sec
|
||||
BoxingBenchmark.primitive_seq:gc.alloc.rate.norm avgt 5 185.884 ± 0.113 B/op
|
||||
BoxingBenchmark.primitive_seq:gc.count avgt 5 ≈ 0 counts
|
||||
@@ -0,0 +1,201 @@
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.OrderedOpsBenchmark.distinct_par_ordered
|
||||
|
||||
# Run progress: 0.00% complete, ETA 00:00:48
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 8704.466 us/op
|
||||
# Warmup Iteration 2: 9269.009 us/op
|
||||
# Warmup Iteration 3: 9734.713 us/op
|
||||
Iteration 1: 9733.449 us/op
|
||||
Iteration 2: 9639.780 us/op
|
||||
Iteration 3: 8957.786 us/op
|
||||
Iteration 4: 11247.905 us/op
|
||||
Iteration 5: 9896.392 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.OrderedOpsBenchmark.distinct_par_ordered":
|
||||
9895.062 ±(99.9%) 3221.657 us/op [Average]
|
||||
(min, avg, max) = (8957.786, 9895.062, 11247.905), stdev = 836.654
|
||||
CI (99.9%): [6673.405, 13116.719] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.OrderedOpsBenchmark.distinct_par_unordered
|
||||
|
||||
# Run progress: 16.67% complete, ETA 00:00:41
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 13742.908 us/op
|
||||
# Warmup Iteration 2: 7226.162 us/op
|
||||
# Warmup Iteration 3: 5339.945 us/op
|
||||
Iteration 1: 6457.032 us/op
|
||||
Iteration 2: 7957.638 us/op
|
||||
Iteration 3: 5756.201 us/op
|
||||
Iteration 4: 6078.999 us/op
|
||||
Iteration 5: 5919.050 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.OrderedOpsBenchmark.distinct_par_unordered":
|
||||
6433.784 ±(99.9%) 3429.350 us/op [Average]
|
||||
(min, avg, max) = (5756.201, 6433.784, 7957.638), stdev = 890.591
|
||||
CI (99.9%): [3004.434, 9863.134] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.OrderedOpsBenchmark.distinct_seq
|
||||
|
||||
# Run progress: 33.33% complete, ETA 00:00:33
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 4882.585 us/op
|
||||
# Warmup Iteration 2: 4988.734 us/op
|
||||
# Warmup Iteration 3: 4556.600 us/op
|
||||
Iteration 1: 5324.242 us/op
|
||||
Iteration 2: 5486.219 us/op
|
||||
Iteration 3: 4496.437 us/op
|
||||
Iteration 4: 4425.314 us/op
|
||||
Iteration 5: 4358.564 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.OrderedOpsBenchmark.distinct_seq":
|
||||
4818.155 ±(99.9%) 2083.875 us/op [Average]
|
||||
(min, avg, max) = (4358.564, 4818.155, 5486.219), stdev = 541.176
|
||||
CI (99.9%): [2734.281, 6902.030] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.OrderedOpsBenchmark.limit_par_ordered
|
||||
|
||||
# Run progress: 50.00% complete, ETA 00:00:24
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 258.706 us/op
|
||||
# Warmup Iteration 2: 228.867 us/op
|
||||
# Warmup Iteration 3: 218.050 us/op
|
||||
Iteration 1: 212.607 us/op
|
||||
Iteration 2: 215.389 us/op
|
||||
Iteration 3: 226.594 us/op
|
||||
Iteration 4: 210.350 us/op
|
||||
Iteration 5: 210.371 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.OrderedOpsBenchmark.limit_par_ordered":
|
||||
215.062 ±(99.9%) 26.069 us/op [Average]
|
||||
(min, avg, max) = (210.350, 215.062, 226.594), stdev = 6.770
|
||||
CI (99.9%): [188.993, 241.131] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.OrderedOpsBenchmark.limit_par_unordered
|
||||
|
||||
# Run progress: 66.67% complete, ETA 00:00:16
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 80.165 us/op
|
||||
# Warmup Iteration 2: 57.729 us/op
|
||||
# Warmup Iteration 3: 57.777 us/op
|
||||
Iteration 1: 55.429 us/op
|
||||
Iteration 2: 54.038 us/op
|
||||
Iteration 3: 59.503 us/op
|
||||
Iteration 4: 57.574 us/op
|
||||
Iteration 5: 56.395 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.OrderedOpsBenchmark.limit_par_unordered":
|
||||
56.588 ±(99.9%) 8.020 us/op [Average]
|
||||
(min, avg, max) = (54.038, 56.588, 59.503), stdev = 2.083
|
||||
CI (99.9%): [48.568, 64.608] (assumes normal distribution)
|
||||
|
||||
|
||||
# JMH version: 1.37
|
||||
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
|
||||
# VM invoker: /tmp/tools/jdk-25.0.5+8/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=42575 -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: 1 thread, will synchronize iterations
|
||||
# Benchmark mode: Average time, time/op
|
||||
# Benchmark: com.ankurm.parallelstreams.OrderedOpsBenchmark.limit_seq
|
||||
|
||||
# Run progress: 83.33% complete, ETA 00:00:08
|
||||
# Fork: 1 of 1
|
||||
# Warmup Iteration 1: 63.583 us/op
|
||||
# Warmup Iteration 2: 68.744 us/op
|
||||
# Warmup Iteration 3: 61.862 us/op
|
||||
Iteration 1: 60.503 us/op
|
||||
Iteration 2: 37.577 us/op
|
||||
Iteration 3: 38.935 us/op
|
||||
Iteration 4: 37.643 us/op
|
||||
Iteration 5: 36.974 us/op
|
||||
|
||||
|
||||
Result "com.ankurm.parallelstreams.OrderedOpsBenchmark.limit_seq":
|
||||
42.326 ±(99.9%) 39.223 us/op [Average]
|
||||
(min, avg, max) = (36.974, 42.326, 60.503), stdev = 10.186
|
||||
CI (99.9%): [3.103, 81.549] (assumes normal distribution)
|
||||
|
||||
|
||||
# Run complete. Total time: 00:00:49
|
||||
|
||||
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
|
||||
OrderedOpsBenchmark.distinct_par_ordered avgt 5 9895.062 ± 3221.657 us/op
|
||||
OrderedOpsBenchmark.distinct_par_unordered avgt 5 6433.784 ± 3429.350 us/op
|
||||
OrderedOpsBenchmark.distinct_seq avgt 5 4818.155 ± 2083.875 us/op
|
||||
OrderedOpsBenchmark.limit_par_ordered avgt 5 215.062 ± 26.069 us/op
|
||||
OrderedOpsBenchmark.limit_par_unordered avgt 5 56.588 ± 8.020 us/op
|
||||
OrderedOpsBenchmark.limit_seq avgt 5 42.326 ± 39.223 us/op
|
||||
@@ -0,0 +1,4 @@
|
||||
[INFO] Running com.ankurm.parallelstreams.ParallelStreamsTest
|
||||
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.115 s -- in com.ankurm.parallelstreams.ParallelStreamsTest
|
||||
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
|
||||
[INFO] BUILD SUCCESS
|
||||
@@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.ankurm</groupId>
|
||||
<artifactId>java-core-examples</artifactId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>parallel-streams</artifactId>
|
||||
<name>parallel-streams</name>
|
||||
<description>When parallel streams are slower: JMH benchmarks for the N*Q model, source splitting, boxing and ordered operations, plus runnable demos of common-pool starvation and parallel-stream correctness bugs.</description>
|
||||
|
||||
<properties>
|
||||
<jmh.version>1.37</jmh.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.11.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>benchmarks</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<release>25</release>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.2.5</version>
|
||||
<configuration>
|
||||
<!-- Pin the common pool so the tests behave the same on a 2-vCPU laptop and a 64-core server. -->
|
||||
<argLine>-Djava.util.concurrent.ForkJoinPool.common.parallelism=3</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals><goal>shade</goal></goals>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>org.openjdk.jmh.Main</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regenerates every file in output/. About 25 minutes on 2 vCPUs, almost all of it JMH.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
mkdir -p output
|
||||
mvn -q -B package -DskipTests
|
||||
JMH="java -jar target/benchmarks.jar -f 1 -wi 3 -w 1s -i 5 -r 1s"
|
||||
|
||||
echo "availableProcessors = $(java -cp target/classes com.ankurm.parallelstreams.CpuInfo 2>/dev/null)" > output/00-environment.txt
|
||||
java -version 2>> output/00-environment.txt || true
|
||||
|
||||
java -Djava.util.concurrent.ForkJoinPool.common.parallelism=3 -cp target/classes \
|
||||
com.ankurm.parallelstreams.CorrectnessBugsDemo > output/01-correctness-bugs.txt
|
||||
java -Djava.util.concurrent.ForkJoinPool.common.parallelism=3 -cp target/classes \
|
||||
com.ankurm.parallelstreams.CommonPoolStarvationDemo > output/02-common-pool-starvation.txt
|
||||
$JMH NqBenchmark > output/03-nq-benchmark.txt
|
||||
$JMH SourceBenchmark > output/04-source-benchmark.txt
|
||||
$JMH BoxingBenchmark -prof gc > output/05-boxing-benchmark.txt
|
||||
$JMH OrderedOpsBenchmark > output/06-ordered-ops-benchmark.txt
|
||||
mvn -B test | grep -E 'Tests run|BUILD|ParallelStreamsTest' > output/07-tests.txt
|
||||
|
||||
# Strip JVM environment noise (proxy banner, Unsafe deprecation warnings) from the committed files.
|
||||
sed -i '/^Picked up JAVA_TOOL_OPTIONS/d;/^WARNING:/d' output/*.txt
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# Run one demo class ad hoc, e.g.: ./scripts/run.sh CorrectnessBugsDemo
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
mvn -q -B package -DskipTests
|
||||
java -Djava.util.concurrent.ForkJoinPool.common.parallelism=3 -cp target/classes "com.ankurm.parallelstreams.$1"
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ankurm.parallelstreams;
|
||||
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* A cheap operation (adding numbers) over 1,000,000 elements, with and without boxing. The
|
||||
* question is how much the boxed pipeline costs per element and whether parallel rescues it.
|
||||
* Run with {@code -prof gc} to see the allocation per call.
|
||||
*/
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
@State(Scope.Benchmark)
|
||||
public class BoxingBenchmark {
|
||||
|
||||
static final int N = 1_000_000;
|
||||
|
||||
@Benchmark public long primitive_seq() { return IntStream.range(0, N).asLongStream().sum(); }
|
||||
@Benchmark public long primitive_par() { return IntStream.range(0, N).parallel().asLongStream().sum(); }
|
||||
|
||||
@Benchmark public long boxed_seq() { return IntStream.range(0, N).boxed().mapToLong(Integer::longValue).sum(); }
|
||||
@Benchmark public long boxed_par() { return IntStream.range(0, N).boxed().parallel().mapToLong(Integer::longValue).sum(); }
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package com.ankurm.parallelstreams;
|
||||
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* Every parallel stream in the JVM shares ONE pool: ForkJoinPool.commonPool(). Block its threads
|
||||
* and every other parallel stream (and CompletableFuture.supplyAsync without an executor) slows
|
||||
* down with them.
|
||||
*
|
||||
* <p>Run with {@code -Djava.util.concurrent.ForkJoinPool.common.parallelism=3} so the numbers are
|
||||
* the same on any machine. The tasks sleep instead of burning CPU, which stands in for a blocking
|
||||
* call (HTTP, JDBC) and keeps the result independent of how many cores the host has.
|
||||
*/
|
||||
public class CommonPoolStarvationDemo {
|
||||
|
||||
static void sleep(long ms) {
|
||||
try { Thread.sleep(ms); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
|
||||
}
|
||||
|
||||
/** The "victim": 16 short tasks of 50 ms. Ideal with 4 threads (3 workers + caller): about 200 ms. */
|
||||
static long victimMillis() {
|
||||
long t0 = System.nanoTime();
|
||||
IntStream.range(0, 16).parallel().forEach(i -> sleep(50));
|
||||
return (System.nanoTime() - t0) / 1_000_000;
|
||||
}
|
||||
|
||||
/** The "noisy neighbour": 8 tasks that each block for 2 seconds. */
|
||||
static Thread startNeighbour(boolean ownPool) {
|
||||
Thread t = new Thread(() -> {
|
||||
if (ownPool) {
|
||||
try (ForkJoinPool pool = new ForkJoinPool(3)) {
|
||||
pool.submit(() -> IntStream.range(0, 8).parallel().forEach(i -> sleep(2_000))).join();
|
||||
}
|
||||
} else {
|
||||
IntStream.range(0, 8).parallel().forEach(i -> sleep(2_000));
|
||||
}
|
||||
}, "neighbour");
|
||||
t.start();
|
||||
return t;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("availableProcessors = " + Runtime.getRuntime().availableProcessors());
|
||||
System.out.println("commonPool parallelism = " + ForkJoinPool.getCommonPoolParallelism());
|
||||
victimMillis(); // warm up the pool
|
||||
|
||||
System.out.println();
|
||||
System.out.println("1. Victim alone");
|
||||
System.out.println(" victim took " + victimMillis() + " ms");
|
||||
|
||||
System.out.println();
|
||||
System.out.println("2. Victim while a neighbour BLOCKS the common pool (8 tasks x 2000 ms)");
|
||||
Thread n = startNeighbour(false);
|
||||
sleep(200);
|
||||
System.out.println(" victim took " + victimMillis() + " ms");
|
||||
n.join();
|
||||
|
||||
System.out.println();
|
||||
System.out.println("3. Same neighbour, but it runs in its OWN ForkJoinPool(3)");
|
||||
n = startNeighbour(true);
|
||||
sleep(200);
|
||||
System.out.println(" victim took " + victimMillis() + " ms");
|
||||
n.join();
|
||||
|
||||
System.out.println();
|
||||
System.out.println("4. 20 blocking tasks x 200 ms: parallel stream vs virtual threads");
|
||||
long t0 = System.nanoTime();
|
||||
IntStream.range(0, 20).parallel().forEach(i -> sleep(200));
|
||||
System.out.println(" parallel stream : " + (System.nanoTime() - t0) / 1_000_000 + " ms");
|
||||
t0 = System.nanoTime();
|
||||
try (var ex = Executors.newVirtualThreadPerTaskExecutor()) {
|
||||
for (int i = 0; i < 20; i++) ex.submit(() -> sleep(200));
|
||||
}
|
||||
System.out.println(" virtual threads : " + (System.nanoTime() - t0) / 1_000_000 + " ms");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.ankurm.parallelstreams;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/** Three ways a parallel stream returns the wrong answer without any exception. */
|
||||
public class CorrectnessBugsDemo {
|
||||
|
||||
/** Bug 1: forEach into a non-thread-safe list. Returns how many elements ended up in it. */
|
||||
public static int sharedListSize(int n) {
|
||||
List<Integer> out = new ArrayList<>();
|
||||
try {
|
||||
IntStream.range(0, n).parallel().forEach(out::add);
|
||||
} catch (RuntimeException e) {
|
||||
return -1; // ArrayIndexOutOfBoundsException from a racing resize
|
||||
}
|
||||
return out.size();
|
||||
}
|
||||
|
||||
/** The fix: let the stream do the collecting. Always n. */
|
||||
public static int collectedListSize(int n) {
|
||||
return IntStream.range(0, n).parallel().boxed().collect(Collectors.toList()).size();
|
||||
}
|
||||
|
||||
/** Bug 2: a "reduce" whose identity is not an identity. Sequential adds the 10 once. */
|
||||
public static int sumWithBadIdentity(boolean parallel) {
|
||||
var s = IntStream.rangeClosed(1, 100);
|
||||
return (parallel ? s.parallel() : s).reduce(10, Integer::sum);
|
||||
}
|
||||
|
||||
/** Bug 3: a non-associative accumulator. Subtraction gives different answers per split. */
|
||||
public static int subtract(boolean parallel) {
|
||||
var s = IntStream.rangeClosed(1, 1000);
|
||||
return (parallel ? s.parallel() : s).reduce(0, (a, b) -> a - b);
|
||||
}
|
||||
|
||||
/** Bug 3b: a stateful lambda. A counter shared by parallel workers is a data race. */
|
||||
public static int racyCounter(int n) {
|
||||
int[] counter = {0};
|
||||
IntStream.range(0, n).parallel().forEach(i -> counter[0]++);
|
||||
return counter[0];
|
||||
}
|
||||
|
||||
public static int atomicCounter(int n) {
|
||||
AtomicInteger c = new AtomicInteger();
|
||||
IntStream.range(0, n).parallel().forEach(i -> c.incrementAndGet());
|
||||
return c.get();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int n = 100_000;
|
||||
System.out.println("1. forEach(list::add), n = " + n + ", ten runs (-1 = exception):");
|
||||
StringBuilder sb = new StringBuilder(" sizes: ");
|
||||
for (int i = 0; i < 10; i++) sb.append(sharedListSize(n)).append(' ');
|
||||
System.out.println(sb);
|
||||
System.out.println(" collect(toList()) size: " + collectedListSize(n));
|
||||
System.out.println();
|
||||
System.out.println("2. reduce(10, Integer::sum) over 1..100");
|
||||
System.out.println(" sequential: " + sumWithBadIdentity(false));
|
||||
System.out.println(" parallel : " + sumWithBadIdentity(true));
|
||||
System.out.println();
|
||||
System.out.println("3. reduce(0, (a, b) -> a - b) over 1..1000");
|
||||
System.out.println(" sequential: " + subtract(false));
|
||||
System.out.println(" parallel : " + subtract(true));
|
||||
System.out.println();
|
||||
System.out.println("4. counter[0]++ in forEach, n = " + n);
|
||||
System.out.println(" racy : " + racyCounter(n));
|
||||
System.out.println(" atomic : " + atomicCounter(n));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.ankurm.parallelstreams;
|
||||
|
||||
/** Prints the CPU count and the default common-pool parallelism, for output/00-environment.txt. */
|
||||
public class CpuInfo {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Runtime.getRuntime().availableProcessors()
|
||||
+ " (default commonPool parallelism = "
|
||||
+ java.util.concurrent.ForkJoinPool.getCommonPoolParallelism() + ")");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.ankurm.parallelstreams;
|
||||
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* The "N x Q" model: N elements, Q units of CPU work per element.
|
||||
*
|
||||
* <p>Parallel only wins when N * Q is large enough to pay for splitting, task hand-off and merging.
|
||||
* {@code Blackhole.consumeCPU(q)} burns a calibrated amount of CPU that the JIT cannot remove, so Q
|
||||
* is a dial we control. Run with {@code -prof gc} or plain; the interesting output is the
|
||||
* sequential/parallel pair at each (n, q).
|
||||
*/
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
@State(Scope.Benchmark)
|
||||
public class NqBenchmark {
|
||||
|
||||
@Param({"100", "10000", "1000000"})
|
||||
public int n;
|
||||
|
||||
@Param({"1", "100"})
|
||||
public long q;
|
||||
|
||||
@Benchmark
|
||||
public long sequential() {
|
||||
return IntStream.range(0, n).map(i -> work(i, q)).sum();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public long parallel() {
|
||||
return IntStream.range(0, n).parallel().map(i -> work(i, q)).sum();
|
||||
}
|
||||
|
||||
static int work(int i, long q) {
|
||||
Blackhole.consumeCPU(q);
|
||||
return i & 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.ankurm.parallelstreams;
|
||||
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* Stateful and order-sensitive operations (limit, distinct) preserve encounter order. In a
|
||||
* parallel pipeline that costs buffering and coordination. Calling {@code unordered()} tells the
|
||||
* framework you do not care which elements win, and the cost mostly disappears.
|
||||
*/
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
@State(Scope.Benchmark)
|
||||
public class OrderedOpsBenchmark {
|
||||
|
||||
static final int N = 200_000;
|
||||
|
||||
List<Integer> data;
|
||||
|
||||
@Setup
|
||||
public void setup() {
|
||||
Random r = new Random(42);
|
||||
data = IntStream.range(0, N).map(i -> r.nextInt(50_000)).boxed().toList();
|
||||
}
|
||||
|
||||
@Benchmark public long limit_seq() { return data.stream().filter(x -> x % 3 == 0).limit(5_000).count(); }
|
||||
@Benchmark public long limit_par_ordered() { return data.parallelStream().filter(x -> x % 3 == 0).limit(5_000).count(); }
|
||||
@Benchmark public long limit_par_unordered() { return data.parallelStream().unordered().filter(x -> x % 3 == 0).limit(5_000).count(); }
|
||||
|
||||
@Benchmark public long distinct_seq() { return data.stream().distinct().count(); }
|
||||
@Benchmark public long distinct_par_ordered() { return data.parallelStream().distinct().count(); }
|
||||
@Benchmark public long distinct_par_unordered() { return data.parallelStream().unordered().distinct().count(); }
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.ankurm.parallelstreams;
|
||||
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Same work (n = 100,000 elements, a little CPU each), six different sources. What changes is how
|
||||
* cheaply the source can be split in half: an array or ArrayList splits by index arithmetic;
|
||||
* a LinkedList has to be walked; Stream.iterate cannot be split at all, so the stream framework
|
||||
* copies batches of elements into arrays first.
|
||||
*/
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
@State(Scope.Benchmark)
|
||||
public class SourceBenchmark {
|
||||
|
||||
static final int N = 100_000;
|
||||
static final long Q = 20;
|
||||
|
||||
int[] array;
|
||||
List<Integer> arrayList;
|
||||
List<Integer> linkedList;
|
||||
|
||||
@Setup
|
||||
public void setup() {
|
||||
array = IntStream.range(0, N).toArray();
|
||||
arrayList = new ArrayList<>(Arrays.stream(array).boxed().toList());
|
||||
linkedList = new LinkedList<>(arrayList);
|
||||
}
|
||||
|
||||
static int work(int i) {
|
||||
Blackhole.consumeCPU(Q);
|
||||
return i & 1;
|
||||
}
|
||||
|
||||
@Benchmark public long intArray_seq() { return Arrays.stream(array).map(SourceBenchmark::work).sum(); }
|
||||
@Benchmark public long intArray_par() { return Arrays.stream(array).parallel().map(SourceBenchmark::work).sum(); }
|
||||
|
||||
@Benchmark public long arrayList_seq() { return arrayList.stream().mapToInt(SourceBenchmark::work).sum(); }
|
||||
@Benchmark public long arrayList_par() { return arrayList.parallelStream().mapToInt(SourceBenchmark::work).sum(); }
|
||||
|
||||
@Benchmark public long linkedList_seq() { return linkedList.stream().mapToInt(SourceBenchmark::work).sum(); }
|
||||
@Benchmark public long linkedList_par() { return linkedList.parallelStream().mapToInt(SourceBenchmark::work).sum(); }
|
||||
|
||||
@Benchmark public long iterate_seq() { return Stream.iterate(0, i -> i + 1).limit(N).mapToInt(SourceBenchmark::work).sum(); }
|
||||
@Benchmark public long iterate_par() { return Stream.iterate(0, i -> i + 1).limit(N).parallel().mapToInt(SourceBenchmark::work).sum(); }
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ankurm.parallelstreams;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** Pins the deterministic claims only. No timing assertions: those live in output/. */
|
||||
class ParallelStreamsTest {
|
||||
|
||||
@Test
|
||||
void commonPoolIsPinnedBySurefireArgLine() {
|
||||
assertEquals(3, ForkJoinPool.getCommonPoolParallelism());
|
||||
}
|
||||
|
||||
@Test
|
||||
void collectingIsAlwaysCorrect() {
|
||||
for (int i = 0; i < 20; i++) assertEquals(100_000, CorrectnessBugsDemo.collectedListSize(100_000));
|
||||
}
|
||||
|
||||
@Test
|
||||
void badIdentityChangesParallelResultButNotSequential() {
|
||||
assertEquals(5060, CorrectnessBugsDemo.sumWithBadIdentity(false)); // 5050 + one 10
|
||||
assertNotEquals(5060, CorrectnessBugsDemo.sumWithBadIdentity(true)); // one 10 per leaf
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonAssociativeSubtractionDiffersBetweenModes() {
|
||||
assertEquals(-500_500, CorrectnessBugsDemo.subtract(false));
|
||||
assertNotEquals(-500_500, CorrectnessBugsDemo.subtract(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void atomicCounterIsExact() {
|
||||
assertEquals(100_000, CorrectnessBugsDemo.atomicCounter(100_000));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user