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 android.util.FloatMath; 19 20public class FloatMathBenchmark { 21 22 public float timeFloatMathCeil(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 += FloatMath.ceil(100.123f); 27 } 28 return f; 29 } 30 31 public float timeFloatMathCeil_math(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 += (float) Math.ceil(100.123f); 36 } 37 return f; 38 } 39 40 public float timeFloatMathCos(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.cos(100.123f); 45 } 46 return f; 47 } 48 49 public float timeFloatMathExp(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.exp(100.123f); 54 } 55 return f; 56 } 57 58 public float timeFloatMathFloor(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.floor(100.123f); 63 } 64 return f; 65 } 66 67 public float timeFloatMathHypot(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.hypot(100.123f, 100.123f); 72 } 73 return f; 74 } 75 76 public float timeFloatMathPow(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.pow(10.123f, 10.123f); 81 } 82 return f; 83 } 84 85 public float timeFloatMathSin(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.sin(100.123f); 90 } 91 return f; 92 } 93 94 public float timeFloatMathSqrt(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 += FloatMath.sqrt(100.123f); 99 } 100 return f; 101 } 102 103 public float timeFloatMathSqrt_math(int reps) { 104 // Keep an answer so we don't optimize the method call away. 105 float f = 0.0f; 106 for (int i = 0; i < reps; i++) { 107 f += (float) Math.sqrt(100.123f); 108 } 109 return f; 110 } 111} 112