GraalVM for Java Performance (Windows Developer Build)

# What is [GraalVM](https://www.graalvm.org/)?
High-performance polyglot VM

# Install GraalVM
### Download GraalVM from [OTN] (https://www.oracle.com/technetwork/graalvm/downloads/index.html)
Windows GraalVM Early Adopter
Support for GraalVM on Windows is currently under development. 
Note: You will need to accept the license at the top of the page before downloading: 
[Download GraalVM based on JDK8, preview for Windows (19.0.1) (cksum - 3226557420)](https://download.oracle.com/otn/utilities_drivers/oracle-labs/graalvm-ee-windows-amd64-19.0.1.zip)
### Extract the downloaded file to any directory
```
Expand-Archive "C:\<DOWNLOADED FOLDER>\graalvm-ee-windows-amd64-19.0.1.zip" "C:\Program Files\Java\"
```
### Installation Check
```
PS C:> & 'C:\Program Files\Java\graalvm-ee-19.0.1\bin\java.exe' -version
java.exe : java version "1.8.0_212"
Java(TM) SE Runtime Environment (build 1.8.0_212-b31)
Java HotSpot(TM) GraalVM EE 19.0.1 (build 25.212-b31-jvmci-19-b01, mixed mode)
```

<!--
# Case.1 Performance Check and Compare
1. Compile JDK1.8 + Run JDK1.8
2. Compile JDK1.8 + Run JDK11
3. Compile JDK1.8 + Run GraalVM Java (NOT native)

```java:GraalTest.java
public class GraalTest {
	public static void main(String[] args) {
		try {
			String s = "";
			int x = 0;
			for (int i = 0; i < 100000; i++) {
				x = i + 1;
				s = s + x;
			}
			System.out.println("HELLO GRAALVM!!!" + x);
		} catch (Throwable t) {
			t.printStackTrace();
		}
	}
}
```
Compile GraalTest.java by JDK1.8

```
PS C:> & 'C:\Program Files\Java\jdk1.8.0\bin\javac.exe' -source 1.8 -d C:\Temp GraalTest.java
```

### Run JDK1.8

```
PS C:\Temp> Measure-Command { & 'C:\Program Files\Java\jdk1.8.0\bin\java.exe' GraalTest }
TotalMilliseconds : 5854.9947
TotalMilliseconds : 5832.4753
TotalMilliseconds : 6098.0974
TotalMilliseconds : 5845.2103
TotalMilliseconds : 5861.4335
```

### Run JDK12

```
PS C:\Temp> Measure-Command { & 'C:\Program Files\Java\jdk-12.0.1\bin\java.exe' GraalTest }
TotalMilliseconds : 3144.7322
TotalMilliseconds : 3154.0768
TotalMilliseconds : 3143.5346
TotalMilliseconds : 3104.6148
TotalMilliseconds : 3137.0850
```

### Run GraalVM Java (NOT native)

```
PS C:\Temp>  Measure-Command { & 'C:\Program Files\Java\graalvm-ee-19.0.1\bin\java.exe' GraalTest }
TotalMilliseconds : 8705.5772
TotalMilliseconds : 8486.3084
TotalMilliseconds : 8407.4948
TotalMilliseconds : 8262.7547
TotalMilliseconds : 8391.5344
```
-->

# Case.2 Performance Check and Compare
1. Compile JDK1.8 + Run JDK1.8
2. Compile JDK1.8 + Run JDK11
3. Compile JDK1.8 + Run GraalVM Java (NOT native)

```java:GraalSample.java
public class GraalSample {
    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 < 10000000; i++) {
                total += sentence.chars().filter(Character::isUpperCase).count();
                if (i % 1000000 == 0) {
                    long now = System.currentTimeMillis();
                    System.out.printf("%d (%d ms)%n", i / 1000000, now - last);
                    last = now;
                }
            }
            System.out.printf("total: %d (%d ms)%n", total, System.currentTimeMillis() - start);
        }
    }
}
```
Compile GraalSample.java by JDK1.8

```
PS C:> & 'C:\Program Files\Java\jdk1.8.0\bin\javac.exe' -source 1.8 -d C:\Temp GraalSample.java
```

### Run JDK1.8

```
PS C:\Temp> Measure-Command { & 'C:\Program Files\Java\jdk1.8.0\bin\java.exe' GraalSample }
TotalMilliseconds : 1272.6506
TotalMilliseconds : 1157.0957
TotalMilliseconds : 1155.1402
TotalMilliseconds : 1165.2418
TotalMilliseconds : 1176.3292

PS C:\Temp> Measure-Command { & 'C:\Program Files\Java\jdk1.8.0\bin\java.exe' GraalSample In 2019 I would like to run ALL languages in one VM.}
TotalMilliseconds : 3806.2965
TotalMilliseconds : 3795.3136
TotalMilliseconds : 3800.0122
TotalMilliseconds : 3791.7407
TotalMilliseconds : 3783.8776
```

<!--
### Run JDK12

```
PS C:\Temp> Measure-Command { & 'C:\Program Files\Java\jdk-12.0.1\bin\java.exe' GraalSample }
TotalMilliseconds : 774.5399
TotalMilliseconds : 775.4765
TotalMilliseconds : 696.2031
TotalMilliseconds : 708.9182
TotalMilliseconds : 726.858

PS C:\Temp> Measure-Command { & 'C:\Program Files\Java\jdk-12.0.1\bin\java.exe' GraalSample In 2019 I would like to run ALL languages in one VM. }
TotalMilliseconds : 2533.3906
TotalMilliseconds : 2650.2566
TotalMilliseconds : 2537.7169
TotalMilliseconds : 2547.0126
TotalMilliseconds : 2539.7377
```
-->

### Run GraalVM Java (NOT native)

```
PS C:\Temp>  Measure-Command { & 'C:\Program Files\Java\graalvm-ee-19.0.1\bin\java.exe' GraalSample }
TotalMilliseconds : 2400.0316
TotalMilliseconds : 2394.7220
TotalMilliseconds : 2413.2863
TotalMilliseconds : 2372.2009
TotalMilliseconds : 2870.4932

PS C:\Temp>  Measure-Command { & 'C:\Program Files\Java\graalvm-ee-19.0.1\bin\java.exe' GraalSample In 2019 I would like to run ALL languages in one VM. }
TotalMilliseconds : 3579.2619
TotalMilliseconds : 3628.8374
TotalMilliseconds : 3516.2905
TotalMilliseconds : 3453.3161
TotalMilliseconds : 3655.8266
```

# Conclusion

GraalVM takes overhead for the first few times, BUT GraalVM is more stable and **FASTER** than JDK1.8, as the number of iterations increase.
It seems GraalVM isn't suitable for single-shot like a simple cli java programs.