Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/micro/org/openjdk/bench/vm/compiler/Signum.java
41161 views
1
/*
2
* Copyright (c) Intel, 2021 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;
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.OperationsPerInvocation;
32
import org.openjdk.jmh.annotations.OutputTimeUnit;
33
import org.openjdk.jmh.annotations.Scope;
34
import org.openjdk.jmh.annotations.State;
35
import org.openjdk.jmh.annotations.Warmup;
36
import org.openjdk.jmh.infra.Blackhole;
37
38
import java.util.concurrent.TimeUnit;
39
40
@BenchmarkMode(Mode.AverageTime)
41
@OutputTimeUnit(TimeUnit.NANOSECONDS)
42
@State(Scope.Thread)
43
@Warmup(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
44
@Measurement(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
45
@Fork(3)
46
public class Signum {
47
48
private final int ITERATIONS = 15000;
49
50
private double doubleValue = 1D;
51
private float floatValue = 1F;
52
53
private static final float[] float_values = {
54
123.4f,
55
-56.7f,
56
7e30f,
57
-0.3e30f,
58
Float.MAX_VALUE,
59
-Float.MAX_VALUE,
60
Float.MIN_VALUE,
61
-Float.MIN_VALUE,
62
0.0f,
63
-0.0f,
64
Float.POSITIVE_INFINITY,
65
Float.NEGATIVE_INFINITY,
66
Float.NaN,
67
Float.MIN_NORMAL,
68
-Float.MIN_NORMAL,
69
0x0.0002P-126f,
70
-0x0.0002P-126f
71
};
72
73
private static final double[] double_values = {
74
123.4d,
75
-56.7d,
76
7e30d,
77
-0.3e30d,
78
Double.MAX_VALUE,
79
-Double.MAX_VALUE,
80
Double.MIN_VALUE,
81
-Double.MIN_VALUE,
82
0.0d,
83
-0.0d,
84
Double.POSITIVE_INFINITY,
85
Double.NEGATIVE_INFINITY,
86
Double.NaN,
87
Double.MIN_NORMAL,
88
-Double.MIN_NORMAL,
89
0x0.00000001P-1022,
90
-0x0.00000001P-1022,
91
};
92
93
private static double Signum_Kernel(double data)
94
{
95
return Math.signum(data);
96
}
97
98
private static float Signum_Kernel(float data)
99
{
100
return Math.signum(data);
101
}
102
103
@Benchmark
104
@OperationsPerInvocation(ITERATIONS * 17)
105
public void _1_signumFloatTest(Blackhole bh) {
106
for (int i = 0; i < ITERATIONS; i++) {
107
for (float f : float_values) {
108
bh.consume(Signum_Kernel(f));
109
}
110
}
111
}
112
113
@Benchmark
114
@OperationsPerInvocation(ITERATIONS * 17)
115
public void _2_overheadFloat(Blackhole bh) {
116
for (int i = 0; i < ITERATIONS; i++) {
117
for (float f : float_values) {
118
bh.consume(f);
119
}
120
}
121
}
122
123
@Benchmark
124
@OperationsPerInvocation(ITERATIONS * 17)
125
public void _3_signumDoubleTest(Blackhole bh) {
126
for (int i = 0; i < ITERATIONS; i++) {
127
for (double d : double_values) {
128
bh.consume(Signum_Kernel(d));
129
}
130
}
131
}
132
133
@Benchmark
134
@OperationsPerInvocation(ITERATIONS * 17)
135
public void _4_overheadDouble(Blackhole bh) {
136
for (int i = 0; i < ITERATIONS; i++) {
137
for (double d : double_values) {
138
bh.consume(d);
139
}
140
}
141
}
142
}
143
144