FloatMathBenchmark.java revision 32b88b48daa7383880088246d7222dd93cf55285
1package android.util;
2
3import com.google.caliper.Param;
4import com.google.caliper.Runner;
5import com.google.caliper.SimpleBenchmark;
6
7import android.util.FloatMath;
8
9import dalvik.system.VMDebug;
10
11public class FloatMathBenchmark extends SimpleBenchmark {
12
13    public float timeFloatMathCeil(int reps) {
14        // Keep an answer so we don't optimize the method call away.
15        float f = 0.0f;
16        for (int i = 0; i < reps; i++) {
17            f += FloatMath.ceil(100.123f);
18        }
19        return f;
20    }
21
22    public float timeFloatMathCeil_math(int reps) {
23        // Keep an answer so we don't optimize the method call away.
24        float f = 0.0f;
25        for (int i = 0; i < reps; i++) {
26            f += (float) Math.ceil(100.123f);
27        }
28        return f;
29    }
30
31    public float timeFloatMathCos(int reps) {
32        // Keep an answer so we don't optimize the method call away.
33        float f = 0.0f;
34        for (int i = 0; i < reps; i++) {
35            f += FloatMath.cos(100.123f);
36        }
37        return f;
38    }
39
40    public float timeFloatMathExp(int reps) {
41        // Keep an answer so we don't optimize the method call away.
42        float f = 0.0f;
43        for (int i = 0; i < reps; i++) {
44            f += FloatMath.exp(100.123f);
45        }
46        return f;
47    }
48
49    public float timeFloatMathFloor(int reps) {
50        // Keep an answer so we don't optimize the method call away.
51        float f = 0.0f;
52        for (int i = 0; i < reps; i++) {
53            f += FloatMath.floor(100.123f);
54        }
55        return f;
56    }
57
58    public float timeFloatMathHypot(int reps) {
59        // Keep an answer so we don't optimize the method call away.
60        float f = 0.0f;
61        for (int i = 0; i < reps; i++) {
62            f += FloatMath.hypot(100.123f, 100.123f);
63        }
64        return f;
65    }
66
67    public float timeFloatMathPow(int reps) {
68        // Keep an answer so we don't optimize the method call away.
69        float f = 0.0f;
70        for (int i = 0; i < reps; i++) {
71            f += FloatMath.pow(10.123f, 10.123f);
72        }
73        return f;
74    }
75
76    public float timeFloatMathSin(int reps) {
77        // Keep an answer so we don't optimize the method call away.
78        float f = 0.0f;
79        for (int i = 0; i < reps; i++) {
80            f += FloatMath.sin(100.123f);
81        }
82        return f;
83    }
84
85    public float timeFloatMathSqrt(int reps) {
86        // Keep an answer so we don't optimize the method call away.
87        float f = 0.0f;
88        for (int i = 0; i < reps; i++) {
89            f += FloatMath.sqrt(100.123f);
90        }
91        return f;
92    }
93
94    public float timeFloatMathSqrt_math(int reps) {
95        // Keep an answer so we don't optimize the method call away.
96        float f = 0.0f;
97        for (int i = 0; i < reps; i++) {
98            f += (float) Math.sqrt(100.123f);
99        }
100        return f;
101    }
102
103}
104