You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: streams/README.md
+23-12Lines changed: 23 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Abstraction Without Regret When Running on GraalVM
1
+
# Java Streams API Benchmark on GraalVM
2
2
3
3
This demo shows how GraalVM efficiently removes abstractions from high-level programs.
4
4
The `Streams.java` file contains a simple query implemented with the Java Streams API:
@@ -21,32 +21,35 @@ Arrays.stream(persons)
21
21
java Streams 100000 200
22
22
```
23
23
```
24
-
Iteration 20 finished in219 milliseconds with checksum e6e0b70aee921601
25
-
TOTAL time: 4717
24
+
Iteration 20 finished in114 milliseconds with checksum e6e0b70aee921601
25
+
TOTAL time: 2330
26
26
```
27
27
28
-
2. Download and install the latest GraalVM JDK with Native Image using the [GraalVM JDK Downloader](https://github.com/graalvm/graalvm-jdk-downloader):
28
+
2. Download and install the latest GraalVM JDK using [SDKMAN!](https://sdkman.io/).
29
29
```bash
30
-
bash <(curl -sL https://get.graalvm.org/jdk)
30
+
sdk install java 21.0.1-graal
31
+
```
31
32
32
33
3. Now compile and run the same application on GraalVM:
33
34
```bash
34
35
$JAVA_HOME/bin/javac Streams.java
35
36
```
36
37
```bash
37
-
$JAVA_HOME/bin/java Streams
38
+
$JAVA_HOME/bin/java Streams 100000 200
38
39
```
39
40
```
40
-
Iteration 20 finished in36 milliseconds with checksum e6e0b70aee921601
41
-
TOTAL time: 1271
41
+
Iteration 20 finished in21 milliseconds with checksum e6e0b70aee921601
42
+
TOTAL time: 623
42
43
```
43
44
44
45
We can see over 4x speedup on this simple program.
45
46
46
47
## Profile-Guided Optimizations with Native Image
47
48
48
49
This demo shows how to use profile-guided optimizations (PGO) with the `native-image` builder.
50
+
49
51
> Note: Profile-guided optimizations is a GraalVM Enterprise feature.
52
+
50
53
You will use the same `Streams.java` program that contains a simple query implemented with the Java Streams API:
51
54
```java
52
55
Arrays.stream(persons)
@@ -69,8 +72,8 @@ Arrays.stream(persons)
69
72
./streams 100000 200
70
73
```
71
74
```
72
-
Iteration 20 finished in452 milliseconds with checksum e6e0b70aee921601
73
-
TOTAL time: 4747
75
+
Iteration 20 finished in127 milliseconds with checksum e6e0b70aee921601
76
+
TOTAL time: 2589
74
77
```
75
78
This version of the program runs about 2x slower than the one on the regular JDK.
76
79
@@ -82,6 +85,10 @@ Arrays.stream(persons)
82
85
```bash
83
86
./streams 10000 200
84
87
```
88
+
```
89
+
Iteration 20 finished in 62 milliseconds with checksum e1d39d010d08cf01
90
+
TOTAL time: 1279
91
+
```
85
92
Profiles collected from this run are now stored in the _default.iprof_ file.
86
93
87
94
Note that we run the profiling with a much smaller data size.
@@ -96,8 +103,12 @@ Arrays.stream(persons)
96
103
./streams 100000 200
97
104
```
98
105
```
99
-
Iteration 20 finished in1 milliseconds with checksum a2708129d726fc01
100
-
TOTAL time: 28
106
+
Iteration 20 finished in24 milliseconds with checksum e6e0b70aee921601
107
+
TOTAL time: 516
101
108
```
102
109
103
110
You should get the performance comparable to the Java version of the program.
111
+
112
+
## Related Documentation
113
+
114
+
[Optimize a Native Executable with PGO](https://www.graalvm.org/latest/reference-manual/native-image/guides/optimize-native-executable-with-pgo/)
0 commit comments