Skip to content

Commit 0a06b63

Browse files
authored
Merge pull request #245 from graalvm/ls/streams_demo
Upgrade Streams Demo.
2 parents bc00992 + bd82cd6 commit 0a06b63

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

.github/workflows/streams.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
timeout-minutes: 15
1818
strategy:
1919
matrix:
20-
java-version: ['17', '20']
20+
java-version: ['21']
2121
steps:
2222
- uses: actions/checkout@v3
2323
- uses: graalvm/setup-graalvm@v1

streams/README.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Abstraction Without Regret When Running on GraalVM
1+
# Java Streams API Benchmark on GraalVM
22

33
This demo shows how GraalVM efficiently removes abstractions from high-level programs.
44
The `Streams.java` file contains a simple query implemented with the Java Streams API:
@@ -21,32 +21,35 @@ Arrays.stream(persons)
2121
java Streams 100000 200
2222
```
2323
```
24-
Iteration 20 finished in 219 milliseconds with checksum e6e0b70aee921601
25-
TOTAL time: 4717
24+
Iteration 20 finished in 114 milliseconds with checksum e6e0b70aee921601
25+
TOTAL time: 2330
2626
```
2727

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/).
2929
```bash
30-
bash <(curl -sL https://get.graalvm.org/jdk)
30+
sdk install java 21.0.1-graal
31+
```
3132

3233
3. Now compile and run the same application on GraalVM:
3334
```bash
3435
$JAVA_HOME/bin/javac Streams.java
3536
```
3637
```bash
37-
$JAVA_HOME/bin/java Streams
38+
$JAVA_HOME/bin/java Streams 100000 200
3839
```
3940
```
40-
Iteration 20 finished in 36 milliseconds with checksum e6e0b70aee921601
41-
TOTAL time: 1271
41+
Iteration 20 finished in 21 milliseconds with checksum e6e0b70aee921601
42+
TOTAL time: 623
4243
```
4344

4445
We can see over 4x speedup on this simple program.
4546

4647
## Profile-Guided Optimizations with Native Image
4748

4849
This demo shows how to use profile-guided optimizations (PGO) with the `native-image` builder.
50+
4951
> Note: Profile-guided optimizations is a GraalVM Enterprise feature.
52+
5053
You will use the same `Streams.java` program that contains a simple query implemented with the Java Streams API:
5154
```java
5255
Arrays.stream(persons)
@@ -69,8 +72,8 @@ Arrays.stream(persons)
6972
./streams 100000 200
7073
```
7174
```
72-
Iteration 20 finished in 452 milliseconds with checksum e6e0b70aee921601
73-
TOTAL time: 4747
75+
Iteration 20 finished in 127 milliseconds with checksum e6e0b70aee921601
76+
TOTAL time: 2589
7477
```
7578
This version of the program runs about 2x slower than the one on the regular JDK.
7679
@@ -82,6 +85,10 @@ Arrays.stream(persons)
8285
```bash
8386
./streams 10000 200
8487
```
88+
```
89+
Iteration 20 finished in 62 milliseconds with checksum e1d39d010d08cf01
90+
TOTAL time: 1279
91+
```
8592
Profiles collected from this run are now stored in the _default.iprof_ file.
8693
8794
Note that we run the profiling with a much smaller data size.
@@ -96,8 +103,12 @@ Arrays.stream(persons)
96103
./streams 100000 200
97104
```
98105
```
99-
Iteration 20 finished in 1 milliseconds with checksum a2708129d726fc01
100-
TOTAL time: 28
106+
Iteration 20 finished in 24 milliseconds with checksum e6e0b70aee921601
107+
TOTAL time: 516
101108
```
102109
103110
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

Comments
 (0)