forked from Dragicafit/JIT-GraalVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Blender3.java
67 lines (57 loc) · 1.33 KB
/
Blender3.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
public class Blender3 {
private static boolean b;
private static class Color {
double r, g, b;
private Color(double r, double g, double b) {
this.r = r;
this.g = g;
this.b = b;
}
public static Color color() {
return new Color(0, 0, 0);
}
public void add(Color other) {
r += other.r;
g += other.g;
b += other.b;
}
public void add(double nr, double ng, double nb) {
r += nr;
g += ng;
b += nb;
}
public void multiply(double factor) {
r *= factor;
g *= factor;
b *= factor;
}
}
private static final Color[][][] colors = new Color[100][100][100];
public static void main(String[] args) {
b=args.length==1;
for (int j = 0; j < 10; j++) {
long t = System.nanoTime();
for (int i = 0; i < 100; i++) {
initialize(new Color(j / 20, 0, 1));
}
long d = System.nanoTime() - t;
System.out.println(d / 1_000_000 + " ms");
}
}
private static void initialize(Color id) {
for (int x = 0; x < colors.length; x++) {
Color[][] plane = colors[x];
for (int y = 0; y < plane.length; y++) {
Color[] row = plane[y];
for (int z = 0; z < row.length; z++) {
Color color = new Color(x, y, z);
color.add(id);
if (!b && (color.r + color.g + color.b) % 42 == 0) {
// PEA only allocates a color object here
row[z] = color;
}
}
}
}
}
}