]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/platform-bionic.git/blob - benchmarks/math_benchmark.cpp
Merge "Remove t->tls==NULL check in pthread_key_delete."
[android-sdk/platform-bionic.git] / benchmarks / math_benchmark.cpp
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  */
17 #include "benchmark.h"
19 #include <fenv.h>
20 #include <math.h>
22 // Avoid optimization.
23 volatile double d;
24 volatile double v;
26 static void BM_math_sqrt(int iters) {
27   StartBenchmarkTiming();
29   d = 0.0;
30   v = 2.0;
31   for (int i = 0; i < iters; ++i) {
32     d += sqrt(v);
33   }
35   StopBenchmarkTiming();
36 }
37 BENCHMARK(BM_math_sqrt);
39 static void BM_math_log10(int iters) {
40   StartBenchmarkTiming();
42   d = 0.0;
43   v = 1234.0;
44   for (int i = 0; i < iters; ++i) {
45     d += log10(v);
46   }
48   StopBenchmarkTiming();
49 }
50 BENCHMARK(BM_math_log10);
52 static void BM_math_logb(int iters) {
53   StartBenchmarkTiming();
55   d = 0.0;
56   v = 1234.0;
57   for (int i = 0; i < iters; ++i) {
58     d += logb(v);
59   }
61   StopBenchmarkTiming();
62 }
63 BENCHMARK(BM_math_logb);
65 static void BM_math_isinf_NORMAL(int iters) {
66   StartBenchmarkTiming();
68   d = 0.0;
69   v = 1234.0; // FP_NORMAL
70   for (int i = 0; i < iters; ++i) {
71     d += (isinf)(v);
72   }
74   StopBenchmarkTiming();
75 }
76 BENCHMARK(BM_math_isinf_NORMAL);
78 static void BM_math_isinf_NAN(int iters) {
79   StartBenchmarkTiming();
81   d = 0.0;
82   v = nan(""); // FP_NAN
83   for (int i = 0; i < iters; ++i) {
84     d += (isinf)(v);
85   }
87   StopBenchmarkTiming();
88 }
89 BENCHMARK(BM_math_isinf_NAN);
91 static void BM_math_isinf_INFINITE(int iters) {
92   StartBenchmarkTiming();
94   d = 0.0;
95   v = HUGE_VAL; // FP_INFINITE
96   for (int i = 0; i < iters; ++i) {
97     d += (isinf)(v);
98   }
100   StopBenchmarkTiming();
102 BENCHMARK(BM_math_isinf_INFINITE);
104 static void BM_math_isinf_ZERO(int iters) {
105   StartBenchmarkTiming();
107   d = 0.0;
108   v = 0.0; // FP_ZERO
109   for (int i = 0; i < iters; ++i) {
110     d += (isinf)(v);
111   }
113   StopBenchmarkTiming();
115 BENCHMARK(BM_math_isinf_ZERO);
117 static void BM_math_sin_fast(int iters) {
118   StartBenchmarkTiming();
120   d = 1.0;
121   for (int i = 0; i < iters; ++i) {
122     d += sin(d);
123   }
125   StopBenchmarkTiming();
127 BENCHMARK(BM_math_sin_fast);
129 static void BM_math_sin_feupdateenv(int iters) {
130   StartBenchmarkTiming();
132   d = 1.0;
133   for (int i = 0; i < iters; ++i) {
134     fenv_t __libc_save_rm;
135     feholdexcept(&__libc_save_rm);
136     fesetround(FE_TONEAREST);
137     d += sin(d);
138     feupdateenv(&__libc_save_rm);
139   }
141   StopBenchmarkTiming();
143 BENCHMARK(BM_math_sin_feupdateenv);
145 static void BM_math_sin_fesetenv(int iters) {
146   StartBenchmarkTiming();
148   d = 1.0;
149   for (int i = 0; i < iters; ++i) {
150     fenv_t __libc_save_rm;
151     feholdexcept(&__libc_save_rm);
152     fesetround(FE_TONEAREST);
153     d += sin(d);
154     fesetenv(&__libc_save_rm);
155   }
157   StopBenchmarkTiming();
159 BENCHMARK(BM_math_sin_fesetenv);
161 static void BM_math_fpclassify_NORMAL(int iters) {
162   StartBenchmarkTiming();
164   d = 0.0;
165   v = 1234.0; // FP_NORMAL
166   for (int i = 0; i < iters; ++i) {
167     d += fpclassify(v);
168   }
170   StopBenchmarkTiming();
172 BENCHMARK(BM_math_fpclassify_NORMAL);
174 static void BM_math_fpclassify_NAN(int iters) {
175   StartBenchmarkTiming();
177   d = 0.0;
178   v = nan(""); // FP_NAN
179   for (int i = 0; i < iters; ++i) {
180     d += fpclassify(v);
181   }
183   StopBenchmarkTiming();
185 BENCHMARK(BM_math_fpclassify_NAN);
187 static void BM_math_fpclassify_INFINITE(int iters) {
188   StartBenchmarkTiming();
190   d = 0.0;
191   v = HUGE_VAL; // FP_INFINITE
192   for (int i = 0; i < iters; ++i) {
193     d += fpclassify(v);
194   }
196   StopBenchmarkTiming();
198 BENCHMARK(BM_math_fpclassify_INFINITE);
200 static void BM_math_fpclassify_ZERO(int iters) {
201   StartBenchmarkTiming();
203   d = 0.0;
204   v = 0.0; // FP_ZERO
205   for (int i = 0; i < iters; ++i) {
206     d += fpclassify(v);
207   }
209   StopBenchmarkTiming();
211 BENCHMARK(BM_math_fpclassify_ZERO);