1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package android.util;
17
18import com.google.caliper.Param;
19import com.google.caliper.Runner;
20import com.google.caliper.SimpleBenchmark;
21
22import android.util.FloatMath;
23
24public class FloatMathBenchmark extends SimpleBenchmark {
25
26    public float timeFloatMathCeil(int reps) {
27        // Keep an answer so we don't optimize the method call away.
28        float f = 0.0f;
29        for (int i = 0; i < reps; i++) {
30            f += FloatMath.ceil(100.123f);
31        }
32        return f;
33    }
34
35    public float timeFloatMathCeil_math(int reps) {
36        // Keep an answer so we don't optimize the method call away.
37        float f = 0.0f;
38        for (int i = 0; i < reps; i++) {
39            f += (float) Math.ceil(100.123f);
40        }
41        return f;
42    }
43
44    public float timeFloatMathCos(int reps) {
45        // Keep an answer so we don't optimize the method call away.
46        float f = 0.0f;
47        for (int i = 0; i < reps; i++) {
48            f += FloatMath.cos(100.123f);
49        }
50        return f;
51    }
52
53    public float timeFloatMathExp(int reps) {
54        // Keep an answer so we don't optimize the method call away.
55        float f = 0.0f;
56        for (int i = 0; i < reps; i++) {
57            f += FloatMath.exp(100.123f);
58        }
59        return f;
60    }
61
62    public float timeFloatMathFloor(int reps) {
63        // Keep an answer so we don't optimize the method call away.
64        float f = 0.0f;
65        for (int i = 0; i < reps; i++) {
66            f += FloatMath.floor(100.123f);
67        }
68        return f;
69    }
70
71    public float timeFloatMathHypot(int reps) {
72        // Keep an answer so we don't optimize the method call away.
73        float f = 0.0f;
74        for (int i = 0; i < reps; i++) {
75            f += FloatMath.hypot(100.123f, 100.123f);
76        }
77        return f;
78    }
79
80    public float timeFloatMathPow(int reps) {
81        // Keep an answer so we don't optimize the method call away.
82        float f = 0.0f;
83        for (int i = 0; i < reps; i++) {
84            f += FloatMath.pow(10.123f, 10.123f);
85        }
86        return f;
87    }
88
89    public float timeFloatMathSin(int reps) {
90        // Keep an answer so we don't optimize the method call away.
91        float f = 0.0f;
92        for (int i = 0; i < reps; i++) {
93            f += FloatMath.sin(100.123f);
94        }
95        return f;
96    }
97
98    public float timeFloatMathSqrt(int reps) {
99        // Keep an answer so we don't optimize the method call away.
100        float f = 0.0f;
101        for (int i = 0; i < reps; i++) {
102            f += FloatMath.sqrt(100.123f);
103        }
104        return f;
105    }
106
107    public float timeFloatMathSqrt_math(int reps) {
108        // Keep an answer so we don't optimize the method call away.
109        float f = 0.0f;
110        for (int i = 0; i < reps; i++) {
111            f += (float) Math.sqrt(100.123f);
112        }
113        return f;
114    }
115
116}
117