benchmark
benchmark copied to clipboard
[FR] Compute complexity over template argument
Is your feature request related to a problem? Please describe.
A good implementation of a reciprocal square root should scale at nlog(n) in the number of mantissa bits. So I would like to measure the empirical complexity of my reciprocal square root does in fact satisfy this scaling, over templated arguments:
#include <benchmark/benchmark.h>
#include <boost/multiprecision/float128.hpp>
#include <boost/multiprecision/mpfr.hpp>
template<typename Real>
inline Real rsqrt(Real const & x) {
// dummy implementation:
return 1/sqrt(x);
}
template<typename Real>
void RSqrtBM(benchmark::State& state)
{
Real x = 0.01;
for (auto _ : state) {
benchmark::DoNotOptimize(rsqrt(x));
x += std::numeric_limits<Real>::epsilon();
}
state.SetComplexityN(8*sizeof(Real));
}
BENCHMARK_TEMPLATE(RSqrtBM, float)->Complexity();
BENCHMARK_TEMPLATE(RSqrtBM, double)->Complexity();
BENCHMARK_TEMPLATE(RSqrtBM, long double)->Complexity();
BENCHMARK_TEMPLATE(RSqrtBM, boost::multiprecision::float128)->Complexity();
BENCHMARK_TEMPLATE(RSqrtBM, boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<100>>)->Complexity();
BENCHMARK_TEMPLATE(RSqrtBM, boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<200>>)->Complexity();
BENCHMARK_TEMPLATE(RSqrtBM, boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<300>>)->Complexity();
BENCHMARK_TEMPLATE(RSqrtBM, boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<400>>)->Complexity();
BENCHMARK_TEMPLATE(RSqrtBM, boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<500>>)->Complexity();
BENCHMARK_TEMPLATE(RSqrtBM, boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<1000>>)->Complexity();
BENCHMARK_MAIN();