2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <benchmark/benchmark.h>
22 static const double values[] = { 1234.0, nan(""), HUGE_VAL, 0.0 };
23 static const char* names[] = { "1234.0", "nan", "HUGE_VAL", "0.0" };
25 #define BENCHMARK_COMMON_VALS(name) BENCHMARK(name)->Arg(0)->Arg(1)->Arg(2)->Arg(3)
27 static void SetLabel(benchmark::State& state) {
28 state.SetLabel(names[state.range(0)]);
31 // Avoid optimization.
35 static void BM_math_sqrt(benchmark::State& state) {
38 while (state.KeepRunning()) {
42 BENCHMARK(BM_math_sqrt);
44 static void BM_math_log10(benchmark::State& state) {
47 while (state.KeepRunning()) {
51 BENCHMARK(BM_math_log10);
53 static void BM_math_logb(benchmark::State& state) {
56 while (state.KeepRunning()) {
60 BENCHMARK(BM_math_logb);
62 static void BM_math_isfinite_macro(benchmark::State& state) {
64 v = values[state.range(0)];
65 while (state.KeepRunning()) {
70 BENCHMARK_COMMON_VALS(BM_math_isfinite_macro);
72 #if defined(__BIONIC__)
73 #define test_isfinite __isfinite
75 #define test_isfinite __finite
77 static void BM_math_isfinite(benchmark::State& state) {
79 v = values[state.range(0)];
80 while (state.KeepRunning()) {
81 d += test_isfinite(v);
85 BENCHMARK_COMMON_VALS(BM_math_isfinite);
87 static void BM_math_isinf_macro(benchmark::State& state) {
89 v = values[state.range(0)];
90 while (state.KeepRunning()) {
95 BENCHMARK_COMMON_VALS(BM_math_isinf_macro);
97 static void BM_math_isinf(benchmark::State& state) {
99 v = values[state.range(0)];
100 while (state.KeepRunning()) {
105 BENCHMARK_COMMON_VALS(BM_math_isinf);
107 static void BM_math_isnan_macro(benchmark::State& state) {
109 v = values[state.range(0)];
110 while (state.KeepRunning()) {
115 BENCHMARK_COMMON_VALS(BM_math_isnan_macro);
117 static void BM_math_isnan(benchmark::State& state) {
119 v = values[state.range(0)];
120 while (state.KeepRunning()) {
125 BENCHMARK_COMMON_VALS(BM_math_isnan);
127 static void BM_math_isnormal_macro(benchmark::State& state) {
129 v = values[state.range(0)];
130 while (state.KeepRunning()) {
135 BENCHMARK_COMMON_VALS(BM_math_isnormal_macro);
137 #if defined(__BIONIC__)
138 static void BM_math_isnormal(benchmark::State& state) {
140 v = values[state.range(0)];
141 while (state.KeepRunning()) {
142 d += (__isnormal)(v);
146 BENCHMARK_COMMON_VALS(BM_math_isnormal);
149 static void BM_math_sin_fast(benchmark::State& state) {
151 while (state.KeepRunning()) {
155 BENCHMARK(BM_math_sin_fast);
157 static void BM_math_sin_feupdateenv(benchmark::State& state) {
159 while (state.KeepRunning()) {
160 fenv_t __libc_save_rm;
161 feholdexcept(&__libc_save_rm);
162 fesetround(FE_TONEAREST);
164 feupdateenv(&__libc_save_rm);
167 BENCHMARK(BM_math_sin_feupdateenv);
169 static void BM_math_sin_fesetenv(benchmark::State& state) {
171 while (state.KeepRunning()) {
172 fenv_t __libc_save_rm;
173 feholdexcept(&__libc_save_rm);
174 fesetround(FE_TONEAREST);
176 fesetenv(&__libc_save_rm);
179 BENCHMARK(BM_math_sin_fesetenv);
181 static void BM_math_fpclassify(benchmark::State& state) {
183 v = values[state.range(0)];
184 while (state.KeepRunning()) {
189 BENCHMARK_COMMON_VALS(BM_math_fpclassify);
191 static void BM_math_signbit_macro(benchmark::State& state) {
193 v = values[state.range(0)];
194 while (state.KeepRunning()) {
199 BENCHMARK_COMMON_VALS(BM_math_signbit_macro);
201 static void BM_math_signbit(benchmark::State& state) {
203 v = values[state.range(0)];
204 while (state.KeepRunning()) {
209 BENCHMARK_COMMON_VALS(BM_math_signbit);
211 static void BM_math_fabs_macro(benchmark::State& state) {
213 v = values[state.range(0)];
214 while (state.KeepRunning()) {
219 BENCHMARK_COMMON_VALS(BM_math_fabs_macro);
221 static void BM_math_fabs(benchmark::State& state) {
223 v = values[state.range(0)];
224 while (state.KeepRunning()) {
229 BENCHMARK_COMMON_VALS(BM_math_fabs);