diff options
Diffstat (limited to 'benchmarks/math_benchmark.cpp')
-rw-r--r-- | benchmarks/math_benchmark.cpp | 125 |
1 files changed, 25 insertions, 100 deletions
diff --git a/benchmarks/math_benchmark.cpp b/benchmarks/math_benchmark.cpp index a9748cd..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. -double d; -double v; +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); |