This repository contains the code for a simple Java Stream benchmark to run on a GraalVM JDK.
-
Download and install the latest GraalVM JDK using SDKMAN!.
sdk install java 21.0.1-graal
-
Download or clone the repository and navigate into the
java-simple-stream-benchmark
directory:git clone https://github.com/graalvm/graalvm-demos
cd graalvm-demos/java-simple-stream-benchmark
-
Build the benchmark. You can manually execute
mvn package
, but there is also abuild.sh
script included for your convenience../build.sh
Now you are all set to execute the benchmark and compare the results between different JVMs.
-
To run the benchmark, you need to execute the
target/benchmarks.jar
file. You can run it with the following command:$JAVA_HOME/bin/java -jar target/benchmarks.jar
If you would like to run the benchmark on a different JVM, you can run it with whatever java
you have.
However, if you want to run it on the same JVM, just without the GraalVM compiler, you can simply add the -XX:-UseJVMCICompiler
command line option into the same command.
$JAVA_HOME/bin/java -XX:-UseJVMCICompiler -jar target/benchmarks.jar
This way, the GraalVM compiler will not be used as the JVMCI compiler and the JVM will use its default one.
The benchmark mode is the AverageTime
in nanoseconds per operation, which means lower numbers are better.
Note that the results you see can be influenced by the hardware you are running this benchmark on, the CPU load, and other factors.
Interpret them responsibly.