Skip to content

Commit 2b2a1a7

Browse files
committed
Extend Java Streams Benchmark demo with more steps; Move to compiler category
1 parent bcf2be7 commit 2b2a1a7

File tree

12 files changed

+602
-70
lines changed

12 files changed

+602
-70
lines changed
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
name: java-simple-stream-benchmark
1+
name: compiler/java-stream-benchmark
22
on:
33
push:
44
paths:
5-
- 'java-simple-stream-benchmark/**'
6-
- '.github/workflows/java-simple-stream-benchmark.yml'
5+
- 'compiler/java-stream-benchmark/**'
6+
- '.github/workflows/compiler-java-stream-benchmark.yml'
77
pull_request:
88
paths:
9-
- 'java-simple-stream-benchmark/**'
10-
- '.github/workflows/java-simple-stream-benchmark.yml'
9+
- 'compiler/java-stream-benchmark/**'
10+
- '.github/workflows/compiler-java-stream-benchmark.yml'
1111
schedule:
1212
- cron: "0 0 1 * *" # run every month
1313
workflow_dispatch:
1414
permissions:
1515
contents: read
1616
jobs:
1717
run:
18-
name: Run 'java-simple-stream-benchmark'
18+
name: Run 'compiler/java-stream-benchmark'
1919
runs-on: ubuntu-latest
2020
timeout-minutes: 15
2121
strategy:
2222
matrix:
23-
java-version: ['21', 'dev']
23+
java-version: ['21', '23.0.1']
2424
steps:
2525
- uses: actions/checkout@v4
2626
- uses: graalvm/setup-graalvm@v1
2727
with:
2828
java-version: ${{ matrix.java-version }}
2929
distribution: 'graalvm'
3030
github-token: ${{ secrets.GITHUB_TOKEN }}
31-
- name: Run 'java-simple-stream-benchmark'
31+
- name: Run 'compiler/java-stream-benchmark'
3232
run: |
33-
cd java-simple-stream-benchmark
34-
./build.sh
33+
cd compiler/java-stream-benchmark
3534
./run.sh

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ cd graalvm-demos
4343
<td align="left" width="30%"><a href="/native-image/list-files/">native-image/list-files</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/native-image-list-files.yml"><img alt="native-image/list-files" src="https://github.com/graalvm/graalvm-demos/actions/workflows/native-image-list-files.yml/badge.svg"/></a></td>
4444
<td align="left" width="70%">Demonstrates how to compile a CLI application into a native executable and then apply Profile-Guided Optimizations (PGO) for more performance gains<br><strong>Technologies: </strong>Native Image, PGO
4545
</tr>
46-
<tr>
47-
<td align="left" width="30%"><a href="/java-simple-stream-benchmark/">java-simple-stream-benchmark</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/java-simple-stream-benchmark.yml"><img alt="java-simple-stream-benchmark" src="https://github.com/graalvm/graalvm-demos/actions/workflows/java-simple-stream-benchmark.yml/badge.svg" /></a></td>
48-
<td align="left" width="70%">Demonstrates how the Graal compiler can achieve better performance for highly abstracted programs like those using Streams, Lambdas<br><strong>Technologies: </strong>Graal compiler, C2<br><strong>Reference: </strong><a href="https://luna.oracle.com/lab/d502417b-df66-45be-9fed-a3ac8e3f09b1/steps#task-2-run-demos-java-microbenchmark-harness-jmh">Simple Java Stream Benchmark</a></td>
49-
</tr>
5046
<tr>
5147
<td align="left" width="30%"><a href="/multithreading-demo/">multithreading-demo</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/streams.yml"><img alt="streams" src="https://github.com/graalvm/graalvm-demos/actions/workflows/streams.yml/badge.svg" /></a></td>
5248
<td align="left" width="70%">Demonstrates how to optimize a Java application that does synchronous and asynchronous threads execution<br><strong>Technologies: </strong>Native Image Build Reports, Native Build Tools Maven plugin <br><strong>Reference: </strong><a href="https://medium.com/graalvm/making-sense-of-native-image-contents-741a688dab4d">Making sense of Native Image contents</a></td>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip
18+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Java Stream Benchmark
2+
3+
This repository contains the code for a simple Java Stream benchmark designed to run on a JDK.
4+
5+
## Preparation
6+
7+
1. Download and install the GraalVM JDK using [SDKMAN!](https://sdkman.io/). For other installation options, visit the [Downloads page](https://www.graalvm.org/downloads/).
8+
```bash
9+
sdk install java 23.0.1-graal
10+
```
11+
12+
2. Download or clone the repository and navigate into the benchmark directory:
13+
```bash
14+
git clone https://github.com/graalvm/graalvm-demos
15+
```
16+
```bash
17+
cd graalvm-demos/compiler/java-stream-benchmark
18+
```
19+
20+
## Build the Benchmark
21+
22+
Build the benchmark with Maven:
23+
```bash
24+
./mvnw package
25+
```
26+
Now you can run this benchmark with whatever `java` you have on your machine and compare the results between JVMs.
27+
28+
> **A note about the results**: The benchmark mode is the `AverageTime` in nanoseconds per operation, which means lower numbers are better.
29+
Note that the results you see can be influenced by the hardware you are running this benchmark on, the CPU load, and other factors.
30+
Interpret them responsibly.
31+
32+
## Run the Benchmark
33+
34+
1. Run the benchmark on the **GraalVM JDK with the default JIT compiler (Graal)** by executing the _target/benchmarks.jar_ file:
35+
```bash
36+
java -jar target/benchmarks.jar
37+
```
38+
39+
2. Now **deactivate the Graal compiler** using the `-XX:-UseJVMCICompiler` option and run the benchmark on the same JVM (GraalVM):
40+
```bash
41+
java -XX:-UseJVMCICompiler -jar target/benchmarks.jar
42+
```
43+
This way, the Graal JIT compiler is not be used as the JVMCI compiler and the JVM uses its default one.
44+
45+
## Learn More
46+
47+
Learn more about the Graal JIT compiler from [its official documentation](https://www.graalvm.org/reference-manual/java/compiler/).
48+
49+
Note that starting with Oracle JDK 23, the **Oracle GraalVM JIT compiler (Graal JIT) is now included among the JITs available as part of the Oracle JDK**.
50+
To run a Java application on Oracle JDK with the Graal JIT compiler, pass the `-XX:+UseGraalJIT` option to `java`.
51+
Read more in [this blog post](https://blogs.oracle.com/java/post/including-the-graal-jit-in-oracle-jdk-23).

0 commit comments

Comments
 (0)