Benchmarks for Java Project Loom Virtual threads vs Platform Threads with JDK (openjdk 19 2022-09-20)
Setup instructions for benchmark:
git clone https://github.com/deepu105/java-loom-benchmarks.git
sdk install java 19.ea.36-open
sdk use java 19.ea.36-open
mvn clean verify
java -jar target/benchmarks.jar
These results vary because they were ran on a developer machine with other services running. Also, according to the JMH
docs, to avoid blackholes
(methods that return void). e.g. If you call a method and return void the JVM will optimize
by removing dead code. To ensure the code isn't removed the method returns teh current time.
Below are some results (smaller numbers are better).
Benchmark Mode Cnt Score Error Units
LoomBenchmark.platformThreadPerTask thrpt 5 0.362 ± 0.079 ops/s
LoomBenchmark.platformThreadPool thrpt 5 0.528 ± 0.067 ops/s
LoomBenchmark.virtualThreadPerTask thrpt 5 1.843 ± 0.093 ops/s
LoomBenchmark.platformThreadPerTask avgt 5 5.600 ± 0.768 s/op
LoomBenchmark.platformThreadPool avgt 5 3.887 ± 0.717 s/op
LoomBenchmark.virtualThreadPerTask avgt 5 1.098 ± 0.020 s/op