Elliott Hughes | 9edb3e0 | 2013-02-06 15:47:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | */ |
| 16 | |
| 17 | #include "benchmark.h" |
| 18 | |
| 19 | #include <math.h> |
| 20 | |
| 21 | // Avoid optimization. |
| 22 | double d; |
| 23 | double v; |
| 24 | |
| 25 | static void BM_math_sqrt(int iters) { |
| 26 | StartBenchmarkTiming(); |
| 27 | |
| 28 | d = 0.0; |
| 29 | v = 2.0; |
| 30 | for (int i = 0; i < iters; ++i) { |
| 31 | d += sqrt(v); |
| 32 | } |
| 33 | |
| 34 | StopBenchmarkTiming(); |
| 35 | } |
| 36 | BENCHMARK(BM_math_sqrt); |
| 37 | |
| 38 | static void BM_math_log10(int iters) { |
| 39 | StartBenchmarkTiming(); |
| 40 | |
| 41 | d = 0.0; |
| 42 | v = 1234.0; |
| 43 | for (int i = 0; i < iters; ++i) { |
| 44 | d += log10(v); |
| 45 | } |
| 46 | |
| 47 | StopBenchmarkTiming(); |
| 48 | } |
| 49 | BENCHMARK(BM_math_log10); |
| 50 | |
| 51 | static void BM_math_logb(int iters) { |
| 52 | StartBenchmarkTiming(); |
| 53 | |
| 54 | d = 0.0; |
| 55 | v = 1234.0; |
| 56 | for (int i = 0; i < iters; ++i) { |
| 57 | d += logb(v); |
| 58 | } |
| 59 | |
| 60 | StopBenchmarkTiming(); |
| 61 | } |
| 62 | BENCHMARK(BM_math_logb); |
Elliott Hughes | 02c78a3 | 2014-04-11 17:02:20 -0700 | [diff] [blame^] | 63 | |
| 64 | static void BM_math_isinf_NORMAL(int iters) { |
| 65 | StartBenchmarkTiming(); |
| 66 | |
| 67 | d = 0.0; |
| 68 | v = 1234.0; // FP_NORMAL |
| 69 | for (int i = 0; i < iters; ++i) { |
| 70 | d += (isinf)(v); |
| 71 | } |
| 72 | |
| 73 | StopBenchmarkTiming(); |
| 74 | } |
| 75 | BENCHMARK(BM_math_isinf_NORMAL); |
| 76 | |
| 77 | static void BM_math_isinf_NAN(int iters) { |
| 78 | StartBenchmarkTiming(); |
| 79 | |
| 80 | d = 0.0; |
| 81 | v = nan(""); // FP_NAN |
| 82 | for (int i = 0; i < iters; ++i) { |
| 83 | d += (isinf)(v); |
| 84 | } |
| 85 | |
| 86 | StopBenchmarkTiming(); |
| 87 | } |
| 88 | BENCHMARK(BM_math_isinf_NAN); |
| 89 | |
| 90 | static void BM_math_isinf_INFINITE(int iters) { |
| 91 | StartBenchmarkTiming(); |
| 92 | |
| 93 | d = 0.0; |
| 94 | v = HUGE_VAL; // FP_INFINITE |
| 95 | for (int i = 0; i < iters; ++i) { |
| 96 | d += (isinf)(v); |
| 97 | } |
| 98 | |
| 99 | StopBenchmarkTiming(); |
| 100 | } |
| 101 | BENCHMARK(BM_math_isinf_INFINITE); |
| 102 | |
| 103 | static void BM_math_isinf_ZERO(int iters) { |
| 104 | StartBenchmarkTiming(); |
| 105 | |
| 106 | d = 0.0; |
| 107 | v = 0.0; // FP_ZERO |
| 108 | for (int i = 0; i < iters; ++i) { |
| 109 | d += (isinf)(v); |
| 110 | } |
| 111 | |
| 112 | StopBenchmarkTiming(); |
| 113 | } |
| 114 | BENCHMARK(BM_math_isinf_ZERO); |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | static void BM_math_fpclassify_NORMAL(int iters) { |
| 122 | StartBenchmarkTiming(); |
| 123 | |
| 124 | d = 0.0; |
| 125 | v = 1234.0; // FP_NORMAL |
| 126 | for (int i = 0; i < iters; ++i) { |
| 127 | d += fpclassify(v); |
| 128 | } |
| 129 | |
| 130 | StopBenchmarkTiming(); |
| 131 | } |
| 132 | BENCHMARK(BM_math_fpclassify_NORMAL); |
| 133 | |
| 134 | static void BM_math_fpclassify_NAN(int iters) { |
| 135 | StartBenchmarkTiming(); |
| 136 | |
| 137 | d = 0.0; |
| 138 | v = nan(""); // FP_NAN |
| 139 | for (int i = 0; i < iters; ++i) { |
| 140 | d += fpclassify(v); |
| 141 | } |
| 142 | |
| 143 | StopBenchmarkTiming(); |
| 144 | } |
| 145 | BENCHMARK(BM_math_fpclassify_NAN); |
| 146 | |
| 147 | static void BM_math_fpclassify_INFINITE(int iters) { |
| 148 | StartBenchmarkTiming(); |
| 149 | |
| 150 | d = 0.0; |
| 151 | v = HUGE_VAL; // FP_INFINITE |
| 152 | for (int i = 0; i < iters; ++i) { |
| 153 | d += fpclassify(v); |
| 154 | } |
| 155 | |
| 156 | StopBenchmarkTiming(); |
| 157 | } |
| 158 | BENCHMARK(BM_math_fpclassify_INFINITE); |
| 159 | |
| 160 | static void BM_math_fpclassify_ZERO(int iters) { |
| 161 | StartBenchmarkTiming(); |
| 162 | |
| 163 | d = 0.0; |
| 164 | v = 0.0; // FP_ZERO |
| 165 | for (int i = 0; i < iters; ++i) { |
| 166 | d += fpclassify(v); |
| 167 | } |
| 168 | |
| 169 | StopBenchmarkTiming(); |
| 170 | } |
| 171 | BENCHMARK(BM_math_fpclassify_ZERO); |