Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/micro/org/openjdk/bench/java/lang/StrictMathBench.java
41161 views
1
/*
2
* Copyright (c) 2021, 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
package org.openjdk.bench.java.lang;
24
25
import java.util.concurrent.TimeUnit;
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.OutputTimeUnit;
32
import org.openjdk.jmh.annotations.Scope;
33
import org.openjdk.jmh.annotations.State;
34
import org.openjdk.jmh.annotations.Warmup;
35
36
@Warmup(iterations = 3, time = 5, timeUnit = TimeUnit.SECONDS)
37
@Measurement(iterations = 4, time = 5, timeUnit = TimeUnit.SECONDS)
38
@Fork(2)
39
@OutputTimeUnit(TimeUnit.MILLISECONDS)
40
@BenchmarkMode(Mode.Throughput)
41
@State(Scope.Thread)
42
public class StrictMathBench {
43
44
public int int1 = 1, int2 = 2, int42 = 42, int5 = 5;
45
public long long1 = 1L, long2 = 2L, long747 = 747L, long13 = 13L;
46
public float float1 = 1.0f, float2 = 2.0f, floatNegative99 = -99.0f, float7 = 7.0f, eFloat = 2.718f;
47
public double double1 = 1.0d, double2 = 2.0d, double81 = 81.0d, doubleNegative12 = -12.0d, double4Dot1 = 4.1d;
48
49
@Benchmark
50
public double absDouble() {
51
return StrictMath.abs(doubleNegative12);
52
}
53
54
@Benchmark
55
public int absExactInt() {
56
return StrictMath.absExact(int2);
57
}
58
59
@Benchmark
60
public long absExactLong() {
61
return StrictMath.absExact(long2);
62
}
63
64
@Benchmark
65
public float absFloat() {
66
return StrictMath.abs(floatNegative99);
67
}
68
69
@Benchmark
70
public int absInt() {
71
return StrictMath.abs(int42);
72
}
73
74
@Benchmark
75
public long absLong() {
76
return StrictMath.abs(long13);
77
}
78
79
@Benchmark
80
public double acosDouble() {
81
return StrictMath.acos(double1);
82
}
83
84
@Benchmark
85
public int addExactInt() {
86
return StrictMath.addExact(int42, int5);
87
}
88
89
@Benchmark
90
public long addExactLong() {
91
return StrictMath.addExact(long2, long13);
92
}
93
94
@Benchmark
95
public double asinDouble() {
96
return StrictMath.asin(double1);
97
}
98
99
@Benchmark
100
public double atanDouble() {
101
return StrictMath.atan(double1);
102
}
103
104
@Benchmark
105
public double atan2Double() {
106
return StrictMath.atan2(double1, double2);
107
}
108
109
@Benchmark
110
public double cbrt() {
111
return StrictMath.cbrt(double81);
112
}
113
114
@Benchmark
115
public double ceilDouble() {
116
return StrictMath.ceil(double4Dot1);
117
}
118
119
@Benchmark
120
public double copySignDouble() {
121
return StrictMath.copySign(double81, doubleNegative12);
122
}
123
124
@Benchmark
125
public float copySignFloat() {
126
return StrictMath.copySign(floatNegative99, float1);
127
}
128
129
@Benchmark
130
public double cosDouble() {
131
return StrictMath.cos(double1);
132
}
133
134
@Benchmark
135
public double coshDouble() {
136
return StrictMath.cosh(double2);
137
}
138
139
@Benchmark
140
public int decrementExactInt() {
141
return StrictMath.decrementExact(int42);
142
}
143
144
@Benchmark
145
public long decrementExactLong() {
146
return StrictMath.decrementExact(long747);
147
}
148
149
@Benchmark
150
public double expDouble() {
151
return StrictMath.exp(double4Dot1);
152
}
153
154
@Benchmark
155
public double expm1() {
156
return StrictMath.expm1(doubleNegative12);
157
}
158
159
@Benchmark
160
public double floorDouble() {
161
return StrictMath.floor(doubleNegative12);
162
}
163
164
@Benchmark
165
public int floorDivIntInt() {
166
return StrictMath.floorDiv(int42, int5);
167
}
168
169
@Benchmark
170
public long floorDivLongInt() {
171
return StrictMath.floorDiv(long747, int42);
172
}
173
174
@Benchmark
175
public long floorDivLongLong() {
176
return StrictMath.floorDiv(long747, long13);
177
}
178
179
@Benchmark
180
public int floorModIntInt() {
181
return StrictMath.floorMod(int42, int5);
182
}
183
184
@Benchmark
185
public int floorModLongInt() {
186
return StrictMath.floorMod(long747, int5);
187
}
188
189
@Benchmark
190
public long floorModLongLong() {
191
return StrictMath.floorMod(long747, long13);
192
}
193
194
@Benchmark
195
public double fmaDouble() {
196
return StrictMath.fma(double2, double81, double4Dot1);
197
}
198
199
@Benchmark
200
public float fmaFloat() {
201
return StrictMath.fma(float2, floatNegative99, float7);
202
}
203
204
@Benchmark
205
public int getExponentDouble() {
206
return StrictMath.getExponent(double81);
207
}
208
209
@Benchmark
210
public int getExponentFloat() {
211
return StrictMath.getExponent(float7);
212
}
213
214
@Benchmark
215
public double hypotDouble() {
216
return StrictMath.hypot(double2, double4Dot1);
217
}
218
219
@Benchmark
220
public double IEEERemainderDouble() {
221
return StrictMath.IEEEremainder(double81, double4Dot1);
222
}
223
224
@Benchmark
225
public int IncrementExactInt() {
226
return StrictMath.incrementExact(int42);
227
}
228
229
@Benchmark
230
public long IncrementExactLong() {
231
return StrictMath.incrementExact(long747);
232
}
233
234
@Benchmark
235
public double logDouble() {
236
return StrictMath.log(double81);
237
}
238
239
@Benchmark
240
public double log10Double() {
241
return StrictMath.log10(double81);
242
}
243
244
@Benchmark
245
public double log1pDouble() {
246
return StrictMath.log1p(double81);
247
}
248
249
@Benchmark
250
public int maxInt() {
251
return StrictMath.max(int1, int2);
252
}
253
254
@Benchmark
255
public long maxLong() {
256
return StrictMath.max(long1, long2);
257
}
258
259
@Benchmark
260
public float maxFloat() {
261
return StrictMath.max(float1, float2);
262
}
263
264
@Benchmark
265
public double maxDouble() {
266
return StrictMath.max(double1, doubleNegative12);
267
}
268
269
@Benchmark
270
public int minInt() {
271
return StrictMath.min(int1, int2);
272
}
273
274
@Benchmark
275
public long minLong() {
276
return StrictMath.min(long1, long2);
277
}
278
279
@Benchmark
280
public float minFloat() {
281
return StrictMath.min(float1, floatNegative99);
282
}
283
284
@Benchmark
285
public double minDouble() {
286
return StrictMath.min(double4Dot1, double2);
287
}
288
289
@Benchmark
290
public int multiplyExactInt() {
291
return StrictMath.multiplyExact(int42, int5);
292
}
293
294
@Benchmark
295
public long multiplyExactLongInt() {
296
return StrictMath.multiplyExact(long747, int42);
297
}
298
299
@Benchmark
300
public long multiplyExactLongLong() {
301
return StrictMath.multiplyExact(long747, long13);
302
}
303
304
@Benchmark
305
public long multiplyFullIntInt() {
306
return StrictMath.multiplyFull(int42, int5);
307
}
308
309
@Benchmark
310
public long multiplyHighLongLog() {
311
return StrictMath.multiplyHigh(long747, long13);
312
}
313
314
@Benchmark
315
public int negateExactInt() {
316
return StrictMath.negateExact(int42);
317
}
318
319
@Benchmark
320
public long negateExactLong() {
321
return StrictMath.negateExact(long747);
322
}
323
324
@Benchmark
325
public double nextAfterDoubleDouble() {
326
return StrictMath.nextAfter(double81, double4Dot1);
327
}
328
329
@Benchmark
330
public float nextAfterFloatDouble() {
331
return StrictMath.nextAfter(float7, doubleNegative12);
332
}
333
334
@Benchmark
335
public double nextDownDouble() {
336
return StrictMath.nextDown(float7);
337
}
338
339
@Benchmark
340
public float nextDownFloat() {
341
return StrictMath.nextDown(floatNegative99);
342
}
343
344
@Benchmark
345
public double nextUpDouble() {
346
return StrictMath.nextUp(double81);
347
}
348
349
@Benchmark
350
public float nextUpFloat() {
351
return StrictMath.nextUp(float7);
352
}
353
354
@Benchmark
355
public double powDouble() {
356
return StrictMath.pow(double4Dot1, double2);
357
}
358
359
@Benchmark
360
public double random() {
361
return StrictMath.random();
362
}
363
364
@Benchmark
365
public double rintDouble() {
366
return StrictMath.rint(double4Dot1);
367
}
368
369
@Benchmark
370
public long roundDouble() {
371
return StrictMath.round( StrictMath.PI);
372
}
373
374
@Benchmark
375
public int roundFloat() {
376
return StrictMath.round(eFloat);
377
}
378
379
@Benchmark
380
public double scalbDoubleInt() {
381
return StrictMath.scalb(double81, int2);
382
}
383
384
@Benchmark
385
public float scalbFloatInt() {
386
return StrictMath.scalb(float7, int2);
387
}
388
389
@Benchmark
390
public double sigNumDouble() {
391
return StrictMath.signum(double4Dot1);
392
}
393
394
@Benchmark
395
public double signumFloat() {
396
return StrictMath.signum(floatNegative99);
397
}
398
399
@Benchmark
400
public double sinDouble() {
401
return StrictMath.sin(double1);
402
}
403
404
@Benchmark
405
public double sinhDouble() {
406
return StrictMath.sinh(double4Dot1);
407
}
408
409
@Benchmark
410
public double sqrtDouble() {
411
return StrictMath.sqrt(double4Dot1);
412
}
413
414
@Benchmark
415
public double subtractExactIntInt() {
416
return StrictMath.subtractExact(int42,int5);
417
}
418
419
@Benchmark
420
public double subtractExactLongLong() {
421
return StrictMath.subtractExact(long747,long13);
422
}
423
424
@Benchmark
425
public double tanDouble() {
426
return StrictMath.tan(double1);
427
}
428
429
@Benchmark
430
public double tanhDouble() {
431
return StrictMath.tanh(double1);
432
}
433
434
@Benchmark
435
public double toDegreesDouble() {
436
return StrictMath.toDegrees(double81);
437
}
438
439
@Benchmark
440
public double toIntExactLong() {
441
return StrictMath.toIntExact(long747);
442
}
443
444
@Benchmark
445
public double toRadiansDouble() {
446
return StrictMath.toRadians(double81);
447
}
448
449
@Benchmark
450
public double ulpDouble() {
451
return StrictMath.ulp(double4Dot1);
452
}
453
454
@Benchmark
455
public double ulpFloat() {
456
return StrictMath.ulp(float7);
457
}
458
459
}
460
461