Created
January 29, 2026 21:18
-
-
Save JohnTortugo/d8f87f92d8987b5da5c9e7898ce5f6ee to your computer and use it in GitHub Desktop.
Substring Graal performance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ==================== C2 ==================== | |
| openjdk version "25.0.2" 2026-01-20 LTS | |
| OpenJDK Runtime Environment Corretto-25.0.2.10.1 (build 25.0.2+10-LTS) | |
| OpenJDK 64-Bit Server VM Corretto-25.0.2.10.1 (build 25.0.2+10-LTS, mixed mode, sharing) | |
| Java version: 25.0.2 | |
| String size: 10000 | |
| Substring length: 20 | |
| Iterations: 50000000 | |
| Total time: 756.349 ms | |
| ns/op: 15.13 | |
| ==================== GRAAL CE JIT ==================== | |
| openjdk version "25.0.1" 2025-10-21 | |
| OpenJDK Runtime Environment GraalVM CE 25.1.0-dev+8.1 (build 25.0.1+8-jvmci-25.1-b14) | |
| OpenJDK 64-Bit Server VM GraalVM CE 25.1.0-dev+8.1 (build 25.0.1+8-jvmci-25.1-b14, mixed mode, sharing) | |
| Java version: 25.0.1 | |
| String size: 10000 | |
| Substring length: 20 | |
| Iterations: 50000000 | |
| Total time: 596.560 ms | |
| ns/op: 11.93 | |
| ==================== GRAAL CE NI (run) ==================== | |
| Java version: 25.0.1 | |
| String size: 10000 | |
| Substring length: 20 | |
| Iterations: 50000000 | |
| Total time: 1090.902 ms | |
| ns/op: 21.82 | |
| ==================== GRAAL ORACLE JIT ==================== | |
| java version "25.0.2" 2026-01-20 LTS | |
| Java(TM) SE Runtime Environment Oracle GraalVM 25.0.2+10.1 (build 25.0.2+10-LTS-jvmci-b01) | |
| Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 25.0.2+10.1 (build 25.0.2+10-LTS-jvmci-b01, mixed mode, sharing) | |
| Java version: 25.0.2 | |
| String size: 10000 | |
| Substring length: 20 | |
| Iterations: 50000000 | |
| Total time: 299.411 ms | |
| ns/op: 5.99 | |
| ==================== GRAAL Oracle NI (no PGO, run) ==================== | |
| Java version: 25.0.2 | |
| String size: 10000 | |
| Substring length: 20 | |
| Iterations: 50000000 | |
| Total time: 303.111 ms | |
| ns/op: 6.06 | |
| ---------------------------------------------------------------------- | |
| public class SubstringBenchmark { | |
| static final int STRING_LEN = 10_000; | |
| static final int SUBSTRING_LEN = 20; | |
| static final int STEADY_ITERS = 50_000_000; | |
| static final int WARMUP_ITERS = 10_000_000; | |
| static volatile int blackhole; | |
| public static void main(String[] args) { | |
| String s = createString(STRING_LEN); | |
| System.out.println("Java version: " + System.getProperty("java.version")); | |
| System.out.println("String size: " + STRING_LEN); | |
| System.out.println("Substring length: " + SUBSTRING_LEN); | |
| System.out.println("Iterations: " + STEADY_ITERS); | |
| // Warmup | |
| for (int i = 0; i < WARMUP_ITERS; i++) { | |
| blackhole ^= s.substring(i % (STRING_LEN - SUBSTRING_LEN), | |
| i % (STRING_LEN - SUBSTRING_LEN) + SUBSTRING_LEN) | |
| .length(); | |
| } | |
| // Benchmark | |
| long start = System.nanoTime(); | |
| for (int i = 0; i < STEADY_ITERS; i++) { | |
| int from = i % (STRING_LEN - SUBSTRING_LEN); | |
| String sub = s.substring(from, from + SUBSTRING_LEN); | |
| blackhole ^= sub.length(); | |
| } | |
| long end = System.nanoTime(); | |
| long elapsedNs = end - start; | |
| double nsPerOp = (double) elapsedNs / STEADY_ITERS; | |
| System.out.printf("Total time: %.3f ms%n", elapsedNs / 1_000_000.0); | |
| System.out.printf("ns/op: %.2f%n", nsPerOp); | |
| } | |
| private static String createString(int size) { | |
| char[] chars = new char[size]; | |
| for (int i = 0; i < size; i++) { | |
| chars[i] = (char) ('a' + (i % 26)); | |
| } | |
| return new String(chars); | |
| } | |
| } | |
| ---------------------------------------------------------------------- | |
| echo "==================== C2 ====================" | |
| . /wf/c2.sh | |
| java -version | |
| java -XX:+UnlockExperimentalVMOptions -XX:+Use${gc}GC -Xms4g -Xmx4g ${bench} | |
| echo "==================== GRAAL CE JIT ====================" | |
| . /wf/graal_25_ce.sh | |
| java -version | |
| java -XX:+UnlockExperimentalVMOptions -XX:+Use${gc}GC -Xms4g -Xmx4g ${bench} | |
| echo "==================== GRAAL CE NI (compile) ====================" | |
| native-image --gc=$2 -O3 ${bench} -o ${bench} | |
| echo "==================== GRAAL CE NI (run) ====================" | |
| taskset -c 0 ./${bench} | |
| echo "==================== GRAAL ORACLE JIT ====================" | |
| . /wf/graal_25_oracle.sh | |
| java -version | |
| java -XX:+UnlockExperimentalVMOptions -XX:+Use${gc}GC -Xms4g -Xmx4g ${bench} | |
| echo "==================== GRAAL Oracle NI (compile) ====================" | |
| native-image --gc=$2 -O3 ${bench} -o ${bench} | |
| echo "==================== GRAAL Oracle NI (run) ====================" | |
| taskset -c 0 ./${bench} | |
| ---------------------------------------------------------------------- | |
| @ARM-BENCH ~ $ cat /etc/lsb-release | |
| DISTRIB_ID=Ubuntu | |
| DISTRIB_RELEASE=24.04 | |
| DISTRIB_CODENAME=noble | |
| DISTRIB_DESCRIPTION="Ubuntu 24.04.2 LTS" | |
| ---------------------------------------------------------------------- | |
| instance-type: c7g.metal | |
| ami-id: ami-0c4e709339fa8521a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment