blob: 3602de43b8a5fb403834ae0bde366e24d6a8dcc0 [file] [log] [blame]
Elliott Hughes9edb3e02013-02-06 15:47:09 -08001/*
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.
22double d;
23double v;
24
25static 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}
36BENCHMARK(BM_math_sqrt);
37
38static 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}
49BENCHMARK(BM_math_log10);
50
51static 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}
62BENCHMARK(BM_math_logb);
Elliott Hughes02c78a32014-04-11 17:02:20 -070063
64static 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}
75BENCHMARK(BM_math_isinf_NORMAL);
76
77static 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}
88BENCHMARK(BM_math_isinf_NAN);
89
90static 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}
101BENCHMARK(BM_math_isinf_INFINITE);
102
103static 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}
114BENCHMARK(BM_math_isinf_ZERO);
115
116
117
118
119
120
121static 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}
132BENCHMARK(BM_math_fpclassify_NORMAL);
133
134static 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}
145BENCHMARK(BM_math_fpclassify_NAN);
146
147static 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}
158BENCHMARK(BM_math_fpclassify_INFINITE);
159
160static 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}
171BENCHMARK(BM_math_fpclassify_ZERO);