Skip to content

Commit e36960e

Browse files
caojoshuajyukutyo
authored andcommittedAug 1, 2023
8312420: Integrate Graal's blender micro benchmark
Reviewed-by: dnsimon, thartmann, ksakata
1 parent 0a3c6d6 commit e36960e

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package org.openjdk.bench.vm.compiler.pea;
25+
26+
import org.openjdk.jmh.annotations.Benchmark;
27+
import org.openjdk.jmh.annotations.BenchmarkMode;
28+
import org.openjdk.jmh.annotations.Fork;
29+
import org.openjdk.jmh.annotations.Measurement;
30+
import org.openjdk.jmh.annotations.Mode;
31+
import org.openjdk.jmh.annotations.Param;
32+
import org.openjdk.jmh.annotations.Scope;
33+
import org.openjdk.jmh.annotations.State;
34+
import org.openjdk.jmh.annotations.OutputTimeUnit;
35+
import org.openjdk.jmh.annotations.Warmup;
36+
37+
import java.util.concurrent.TimeUnit;
38+
39+
@BenchmarkMode(Mode.AverageTime)
40+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
41+
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
42+
@Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.SECONDS)
43+
@State(Scope.Benchmark)
44+
@Fork(value = 3)
45+
public class Blender {
46+
@Param({"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"})
47+
int iteration;
48+
49+
private static class Color {
50+
double r, g, b;
51+
52+
private Color(double r, double g, double b) {
53+
this.r = r;
54+
this.g = g;
55+
this.b = b;
56+
}
57+
58+
public static Color color() {
59+
return new Color(0, 0, 0);
60+
}
61+
62+
public void add(Color other) {
63+
r += other.r;
64+
g += other.g;
65+
b += other.b;
66+
}
67+
68+
public void add(double nr, double ng, double nb) {
69+
r += nr;
70+
g += ng;
71+
b += nb;
72+
}
73+
74+
public void multiply(double factor) {
75+
r *= factor;
76+
g *= factor;
77+
b *= factor;
78+
}
79+
}
80+
81+
private static final Color[][][] colors = new Color[100][100][100];
82+
83+
@Benchmark
84+
public void initialize() {
85+
Color id = new Color(iteration / 20, 0, 1);
86+
for (int x = 0; x < colors.length; x++) {
87+
Color[][] plane = colors[x];
88+
for (int y = 0; y < plane.length; y++) {
89+
Color[] row = plane[y];
90+
for (int z = 0; z < row.length; z++) {
91+
Color color = new Color(x, y, z);
92+
color.add(id);
93+
if ((color.r + color.g + color.b) % 42 == 0) {
94+
// PEA only allocates a color object here
95+
row[z] = color;
96+
} else {
97+
// Here the color object is not allocated at all
98+
}
99+
}
100+
}
101+
}
102+
}
103+
}
104+

0 commit comments

Comments
 (0)
Please sign in to comment.