forked from sxs-collaboration/spectre
-
Notifications
You must be signed in to change notification settings - Fork 0
Benchmark Codes
Nils Deppe edited this page Nov 6, 2018
·
1 revision
I prefer to run with:
./bin/Benchmark --benchmark_repetitions=10 --benchmark_report_aggregates_only=true
Note: The headers typically are something like:
#include <benchmark/benchmark.h>
#include <string>
#include <vector>
#include "DataStructures/DataBox/DataBoxTag.hpp"
#include "DataStructures/DataVector.hpp"
#include "DataStructures/Tensor/Tensor.hpp"
#include "DataStructures/Variables.hpp"
#include "Domain/CoordinateMaps/Affine.hpp"
#include "Domain/CoordinateMaps/CoordinateMap.hpp"
#include "Domain/CoordinateMaps/ProductMaps.hpp"
#include "Domain/Element.hpp"
#include "Domain/LogicalCoordinates.hpp"
#include "Domain/Mesh.hpp"
#include "NumericalAlgorithms/LinearOperators/DefiniteIntegral.cpp"
#include "NumericalAlgorithms/LinearOperators/PartialDerivatives.hpp"
#include "NumericalAlgorithms/Spectral/Spectral.hpp"
#include "PointwiseFunctions/MathFunctions/PowX.hpp"
// Charm looks for this function but since we build without a main function or
// main module we just have it be empty
extern "C" void CkRegisterMainModule(void) {}
Note: Using a DenseRange
to iterate over different mesh sizes is very useful. This is done, e.g.
BENCHMARK(bench_2d)->DenseRange(2, 12, 1);
which will iterate from [2, ..., 12]
with a stride of 1
.
namespace {
// clang-tidy: don't pass be non-const reference
void bench_3d(benchmark::State& state) { // NOLINT
const size_t pts_1d = state.range(0);
constexpr const size_t Dim = 3;
const Mesh<Dim> mesh{pts_1d, Spectral::Basis::Legendre,
Spectral::Quadrature::GaussLobatto};
DataVector a(mesh.number_of_grid_points(), 0.0);
for (auto _ : state) {
benchmark::DoNotOptimize(definite_integral(a, mesh));
}
}
BENCHMARK(bench_3d)->DenseRange(2, 12, 1);
void bench_2d(benchmark::State& state) { // NOLINT
const size_t pts_1d = state.range(0);
constexpr const size_t Dim = 2;
const Mesh<Dim> mesh{pts_1d, Spectral::Basis::Legendre,
Spectral::Quadrature::GaussLobatto};
DataVector a(mesh.number_of_grid_points(), 0.0);
for (auto _ : state) {
benchmark::DoNotOptimize(definite_integral(a, mesh));
}
}
BENCHMARK(bench_2d)->DenseRange(2, 12, 1);
} // namespace
BENCHMARK_MAIN();