I'm currently trying java Ahead of Time feature.
I execute the following code:
public class CountUppercase {
static final int ITERATIONS = Math.max(Integer.getInteger("iterations", 1), 1);
public static void main(String[] args) {
String sentence = String.join(" ", args);
for (int iter = 0; iter < ITERATIONS; iter++) {
if (ITERATIONS != 1) System.out.println("-- iteration " + (iter + 1) + " --");
long total = 0, start = System.currentTimeMillis(), last = start;
for (int i = 1; i < 10_000_000; i++) {
total += sentence.chars().filter(Character::isUpperCase).count();
if (i % 1_000_000 == 0) {
long now = System.currentTimeMillis();
System.out.printf("%d (%d ms)%n", i / 1_000_000, now - last);
last = now;
}
}
System.out.printf("total: %d (%d ms)%n", total, System.currentTimeMillis() - start);
}
}
}
I Launch:
[baptiste@KEYWER tuto_aot]$ $JAVA_HOME/bin/java -version
java version "13.0.1" 2019-10-15
Java(TM) SE Runtime Environment (build 13.0.1+9)
Java HotSpot(TM) 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing)
[baptiste@KEYWER tuto_aot]$ $JAVA_HOME/bin/javac CountUppercase.java
[baptiste@KEYWER tuto_aot]$ $JAVA_HOME/bin/java CountUppercase In 2020 I would like to run ALL languages in one VM.
1 (351 ms)
2 (359 ms)
3 (316 ms)
4 (342 ms)
5 (316 ms)
6 (318 ms)
7 (313 ms)
8 (316 ms)
9 (320 ms)
total: 69999993 (3267 ms)
It take only 3267 ms
Now I decide to compile the same code with AOT feature
[baptiste@KEYWER tuto_aot]$ $JAVA_HOME/bin/jaotc --output CountUppercase.so CountUppercase.class
Then I run the AOT:
[baptiste@KEYWER tuto_aot]$ $JAVA_HOME/bin/java -XX:AOTLibrary=./CountUppercase.so CountUppercase In 2020 I would like to run ALL languages in one VM.
1 (581 ms)
2 (503 ms)
3 (486 ms)
4 (505 ms)
5 (483 ms)
6 (486 ms)
7 (483 ms)
8 (490 ms)
9 (481 ms)
total: 69999993 (4981 ms)
It takes 5 seconds so around 2 seconds more than classical execution !
I don't understand why I get this behavior ?
Thx for your time