Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/micro/org/openjdk/bench/java/math/FpRoundingBenchmark.java
41161 views
1
//
2
// Copyright (c) 2003, 2019, 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.java.math;
25
26
import java.util.Random;
27
import java.util.concurrent.TimeUnit;
28
import org.openjdk.jmh.annotations.*;
29
import org.openjdk.jmh.infra.Blackhole;
30
31
@OutputTimeUnit(TimeUnit.MILLISECONDS)
32
@State(Scope.Thread)
33
public class FpRoundingBenchmark {
34
35
@Param({"1024"})
36
public int TESTSIZE;
37
38
public double[] DargV1;
39
40
public double[] Res;
41
42
public final double[] DspecialVals = {
43
0.0, -0.0, Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY};
44
45
@Setup(Level.Trial)
46
public void BmSetup() {
47
int i = 0;
48
Random r = new Random(1024);
49
DargV1 = new double[TESTSIZE];
50
Res = new double[TESTSIZE];
51
52
for (; i < DspecialVals.length; i++) {
53
DargV1[i] = DspecialVals[i];
54
}
55
56
for (; i < TESTSIZE; i++) {
57
DargV1[i] = r.nextDouble()*TESTSIZE;
58
}
59
}
60
61
@Benchmark
62
public void testceil(Blackhole bh) {
63
for (int i = 0; i < TESTSIZE; i++)
64
Res[i] = Math.ceil(DargV1[i]);
65
}
66
67
@Benchmark
68
public void testfloor(Blackhole bh) {
69
for (int i = 0; i < TESTSIZE; i++)
70
Res[i] = Math.floor(DargV1[i]);
71
}
72
73
@Benchmark
74
public void testrint(Blackhole bh) {
75
for (int i = 0; i < TESTSIZE; i++)
76
Res[i] = Math.rint(DargV1[i]);
77
}
78
}
79
80