summaryrefslogtreecommitdiffstats
path: root/benchmarks/math_benchmark.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2015-02-17 19:58:53 -0800
committerChristopher Ferris <cferris@google.com>2015-02-19 14:58:24 -0800
commitdf4942c04a63ae6e4f5c78ece9f696d6b8b74d32 (patch)
treef4e1061bcaf821753263413f1e89fb82f5d50e99 /benchmarks/math_benchmark.cpp
parent3e1b5f46c07aef5983ecf2feb1c3369b2cd200c0 (diff)
downloadbionic-df4942c04a63ae6e4f5c78ece9f696d6b8b74d32.zip
bionic-df4942c04a63ae6e4f5c78ece9f696d6b8b74d32.tar.gz
bionic-df4942c04a63ae6e4f5c78ece9f696d6b8b74d32.tar.bz2
Refactor the benchmark code.
Changes: - Modify the benchmarks to derive from a single Benchmark object. - Rewrite the main iteration code. This includes changing the iteration code to use the actual total time calculated by the benchmark as a basis for determining whether there are enough iterations instead of using the time it takes to run the benchmark. - Allow benchmarks to take no argument, int, or double. - Fix the PrettyInt printer for negative integers. - Modify the max column width name to include the whole name including the arg part. - Reformat property_benchmark.cpp in line with the rest of the code. - Modify a few of the math benchmarks to take an argument instead of separate benchmarks for the same function with different args. - Create a vector of regex_t structs to represent the args all at once instead of when running each benchmark. This change is in preparation for adding new math based benchmarks. Tested by running on a nexus flo running at max using the new code and the old code and comparing. All of the numbers are similar, but some of the iterations are different due to the slightly different algorithm used. Change-Id: I57ad1f3ff083282b9ffeb72e687cab369ce3523a
Diffstat (limited to 'benchmarks/math_benchmark.cpp')
-rw-r--r--benchmarks/math_benchmark.cpp121
1 files changed, 23 insertions, 98 deletions
diff --git a/benchmarks/math_benchmark.cpp b/benchmarks/math_benchmark.cpp
index 8d6dd10..4de28d1 100644
--- a/benchmarks/math_benchmark.cpp
+++ b/benchmarks/math_benchmark.cpp
@@ -14,16 +14,20 @@
* limitations under the License.
*/
-#include "benchmark.h"
-
#include <fenv.h>
#include <math.h>
+#include <benchmark/Benchmark.h>
+
+#define AT_COMMON_VALS \
+ Arg(1234.0)->Arg(nan(""))->Arg(HUGE_VAL)->Arg(0.0)
+
// Avoid optimization.
volatile double d;
volatile double v;
-static void BM_math_sqrt(int iters) {
+BENCHMARK_NO_ARG(BM_math_sqrt);
+void BM_math_sqrt::Run(int iters) {
StartBenchmarkTiming();
d = 0.0;
@@ -34,9 +38,9 @@ static void BM_math_sqrt(int iters) {
StopBenchmarkTiming();
}
-BENCHMARK(BM_math_sqrt);
-static void BM_math_log10(int iters) {
+BENCHMARK_NO_ARG(BM_math_log10);
+void BM_math_log10::Run(int iters) {
StartBenchmarkTiming();
d = 0.0;
@@ -47,9 +51,9 @@ static void BM_math_log10(int iters) {
StopBenchmarkTiming();
}
-BENCHMARK(BM_math_log10);
-static void BM_math_logb(int iters) {
+BENCHMARK_NO_ARG(BM_math_logb);
+void BM_math_logb::Run(int iters) {
StartBenchmarkTiming();
d = 0.0;
@@ -60,61 +64,22 @@ static void BM_math_logb(int iters) {
StopBenchmarkTiming();
}
-BENCHMARK(BM_math_logb);
-
-static void BM_math_isinf_NORMAL(int iters) {
- StartBenchmarkTiming();
-
- d = 0.0;
- v = 1234.0; // FP_NORMAL
- for (int i = 0; i < iters; ++i) {
- d += (isinf)(v);
- }
-
- StopBenchmarkTiming();
-}
-BENCHMARK(BM_math_isinf_NORMAL);
-
-static void BM_math_isinf_NAN(int iters) {
- StartBenchmarkTiming();
-
- d = 0.0;
- v = nan(""); // FP_NAN
- for (int i = 0; i < iters; ++i) {
- d += (isinf)(v);
- }
-
- StopBenchmarkTiming();
-}
-BENCHMARK(BM_math_isinf_NAN);
-static void BM_math_isinf_INFINITE(int iters) {
+BENCHMARK_WITH_ARG(BM_math_isinf, double)->AT_COMMON_VALS;
+void BM_math_isinf::Run(int iters, double value) {
StartBenchmarkTiming();
d = 0.0;
- v = HUGE_VAL; // FP_INFINITE
+ v = value;
for (int i = 0; i < iters; ++i) {
d += (isinf)(v);
}
StopBenchmarkTiming();
}
-BENCHMARK(BM_math_isinf_INFINITE);
-static void BM_math_isinf_ZERO(int iters) {
- StartBenchmarkTiming();
-
- d = 0.0;
- v = 0.0; // FP_ZERO
- for (int i = 0; i < iters; ++i) {
- d += (isinf)(v);
- }
-
- StopBenchmarkTiming();
-}
-BENCHMARK(BM_math_isinf_ZERO);
-
-static void BM_math_sin_fast(int iters) {
+BENCHMARK_NO_ARG(BM_math_sin_fast);
+void BM_math_sin_fast::Run(int iters) {
StartBenchmarkTiming();
d = 1.0;
@@ -124,9 +89,9 @@ static void BM_math_sin_fast(int iters) {
StopBenchmarkTiming();
}
-BENCHMARK(BM_math_sin_fast);
-static void BM_math_sin_feupdateenv(int iters) {
+BENCHMARK_NO_ARG(BM_math_sin_feupdateenv);
+void BM_math_sin_feupdateenv::Run(int iters) {
StartBenchmarkTiming();
d = 1.0;
@@ -140,9 +105,9 @@ static void BM_math_sin_feupdateenv(int iters) {
StopBenchmarkTiming();
}
-BENCHMARK(BM_math_sin_feupdateenv);
-static void BM_math_sin_fesetenv(int iters) {
+BENCHMARK_NO_ARG(BM_math_sin_fesetenv);
+void BM_math_sin_fesetenv::Run(int iters) {
StartBenchmarkTiming();
d = 1.0;
@@ -156,56 +121,16 @@ static void BM_math_sin_fesetenv(int iters) {
StopBenchmarkTiming();
}
-BENCHMARK(BM_math_sin_fesetenv);
-
-static void BM_math_fpclassify_NORMAL(int iters) {
- StartBenchmarkTiming();
-
- d = 0.0;
- v = 1234.0; // FP_NORMAL
- for (int i = 0; i < iters; ++i) {
- d += fpclassify(v);
- }
-
- StopBenchmarkTiming();
-}
-BENCHMARK(BM_math_fpclassify_NORMAL);
-
-static void BM_math_fpclassify_NAN(int iters) {
- StartBenchmarkTiming();
-
- d = 0.0;
- v = nan(""); // FP_NAN
- for (int i = 0; i < iters; ++i) {
- d += fpclassify(v);
- }
-
- StopBenchmarkTiming();
-}
-BENCHMARK(BM_math_fpclassify_NAN);
-
-static void BM_math_fpclassify_INFINITE(int iters) {
- StartBenchmarkTiming();
-
- d = 0.0;
- v = HUGE_VAL; // FP_INFINITE
- for (int i = 0; i < iters; ++i) {
- d += fpclassify(v);
- }
-
- StopBenchmarkTiming();
-}
-BENCHMARK(BM_math_fpclassify_INFINITE);
-static void BM_math_fpclassify_ZERO(int iters) {
+BENCHMARK_WITH_ARG(BM_math_fpclassify, double)->AT_COMMON_VALS;
+void BM_math_fpclassify::Run(int iters, double value) {
StartBenchmarkTiming();
d = 0.0;
- v = 0.0; // FP_ZERO
+ v = value;
for (int i = 0; i < iters; ++i) {
d += fpclassify(v);
}
StopBenchmarkTiming();
}
-BENCHMARK(BM_math_fpclassify_ZERO);