|
| 1 | +#include "Benchmark.h" |
| 2 | + |
| 3 | +// Forward-declare the functions to benchmark |
| 4 | +extern "C" { |
| 5 | +double compute_stats_f(const int n, const double *data, double *mean, |
| 6 | + double *stddev); |
| 7 | +double compute_stats_improved_f(const int n, const double *data, double *mean, |
| 8 | + double *stddev); |
| 9 | +} |
| 10 | + |
| 11 | +// Size adjusted to fit execution on micro-seconds |
| 12 | +constexpr int N = 1024 * 1024; |
| 13 | + |
| 14 | +#if OCB_ENABLE_Fortran |
| 15 | + |
| 16 | +static void FortranExampleBench(benchmark::State &state) { |
| 17 | + auto array = OpenCatalog::CreateRandomVector<double>(N); |
| 18 | + |
| 19 | + for (auto _ : state) { |
| 20 | + double mean, stddev; |
| 21 | + compute_stats_f(N, array.data(), &mean, &stddev); |
| 22 | + benchmark::DoNotOptimize(mean); |
| 23 | + benchmark::DoNotOptimize(stddev); |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +static void FortranImprovedBench(benchmark::State &state) { |
| 28 | + auto array = OpenCatalog::CreateRandomVector<double>(N); |
| 29 | + |
| 30 | + for (auto _ : state) { |
| 31 | + double mean, stddev; |
| 32 | + compute_stats_improved_f(N, array.data(), &mean, &stddev); |
| 33 | + benchmark::DoNotOptimize(mean); |
| 34 | + benchmark::DoNotOptimize(stddev); |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +// The goal of these benchmarks is to demonstrate that the suggested check does |
| 39 | +// not incur any performance penalty |
| 40 | +OC_BENCHMARK("PWR081 Fortran Example", FortranExampleBench); |
| 41 | +OC_BENCHMARK("PWR081 Fortran Improved", FortranImprovedBench); |
| 42 | + |
| 43 | +#endif |
0 commit comments