google / google/benchmark

[FR] Compute complexity over template argument

Open
#967 0 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
10.4k
Forks
1.8k
Avg merge
2d 4h
Merged PRs (30d)
8

Description

**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
#include
#include

template
inline Real rsqrt(Real const & x) {
// dummy implementation:
return 1/sqrt(x);
}

template
void RSqrtBM(benchmark::State& state)
{
Real x = 0.01;
for (auto _ : state) {
benchmark::DoNotOptimize(rsqrt(x));
x += std::numeric_limits::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>)->Complexity();
BENCHMARK_TEMPLATE(RSqrtBM, boost::multiprecision::number>)->Complexity();
BENCHMARK_TEMPLATE(RSqrtBM, boost::multiprecision::number>)->Complexity();
BENCHMARK_TEMPLATE(RSqrtBM, boost::multiprecision::number>)->Complexity();
BENCHMARK_TEMPLATE(RSqrtBM, boost::multiprecision::number>)->Complexity();
BENCHMARK_TEMPLATE(RSqrtBM, boost::multiprecision::number>)->Complexity();

BENCHMARK_MAIN();
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.