Sunday, April 12, 2020

Comparing performance between Java and GraalVM using HelloWorld

// HelloWorld.java

class HelloWorld {
  public static void main(String []args) {
    System.out.println("Hello World!");
  }
}
Compile using Java
[oracle@ol8 graalvm]$ javac HelloWorld.java
Compile the GraalVM native-image
[oracle@ol8 graalvm]$ native-image HelloWorld
Build on Server(pid: 8165, port: 41485)
[helloworld:8165] classlist: 443.81 ms, 1.00 GB
[helloworld:8165] (cap): 3,624.20 ms, 1.47 GB
[helloworld:8165] setup: 6,859.23 ms, 1.47 GB
[helloworld:8165] (typeflow): 15,129.44 ms, 2.51 GB
[helloworld:8165] (objects): 13,985.98 ms, 2.51 GB
[helloworld:8165] (features): 474.70 ms, 2.51 GB
[helloworld:8165] analysis: 30,229.96 ms, 2.51 GB
[helloworld:8165] (clinit): 825.54 ms, 2.51 GB
[helloworld:8165] universe: 1,554.51 ms, 2.51 GB
[helloworld:8165] (parse): 4,234.29 ms, 2.51 GB
[helloworld:8165] (inline): 3,430.47 ms, 2.65 GB
[helloworld:8165] (compile): 27,552.36 ms, 2.65 GB
[helloworld:8165] compile: 36,017.72 ms, 2.65 GB
[helloworld:8165] image: 1,535.45 ms, 2.65 GB
[helloworld:8165] write: 362.66 ms, 2.65 GB
[helloworld:8165] [total]: 77,848.27 ms, 2.65 GB
Check the file type
[oracle@ol8 graalvm]$ file helloworld
helloworld: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=a61b6ddb0c2a51fc2e9fdc748a000ec65b5e5c3d, with debug_info, not stripped, too many notes (256)
Check the file type
[oracle@ol8 graalvm]$ ls -ltrh
total 6.5M
drwxr-xr-x. 10 oracle oinstall 232 Apr 12 21:04 graalvm-ce-java11-20.0.0
-rw-r--r--. 1 oracle oinstall 104 Apr 12 21:10 HelloWorld.java
-rw-r--r--. 1 oracle oinstall 426 Apr 12 21:10 HelloWorld.class
-rwxr-xr-x. 1 oracle oinstall 6.5M Apr 12 21:12 helloworld
Compare single execution time
[oracle@ol8 graalvm]$ time java HelloWorld
Hello World!

real 0m0.167s
user 0m0.189s
sys 0m0.047s

[oracle@ol8 graalvm]$ time ./helloworld
Hello World!

real 0m0.010s
user 0m0.002s
sys 0m0.007s
Compare multiple execution time (using 100 as example)
[oracle@ol8 graalvm]$ cat java.sh
for i in {1..100}
do
  java HelloWorld >/dev/null
done

[oracle@ol8 graalvm]$ time ./java.sh
real 0m15.550s
user 0m17.017s
sys 0m4.643s

[oracle@ol8 graalvm]$ cat graalvm.sh
for i in {1..100}
do
  ./helloworld >/dev/null
done

[oracle@ol8 graalvm]$ time ./graalvm.sh
real 0m0.841s
user 0m0.264s
sys 0m0.538s

No comments:

Post a Comment