2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00

Performance reporting for constants (#366)

* Performance reporting for constants [CI SKIP]

* Remove itrunc overflow. [CI SKIP]
This commit is contained in:
Nick
2020-06-06 09:11:52 -04:00
committed by GitHub
parent 4facb20ff9
commit 4e510da7fd
2 changed files with 150 additions and 2 deletions

View File

@@ -8,7 +8,7 @@
#ifndef BOOST_MATH_CALCULATE_CONSTANTS_CONSTANTS_INCLUDED
#define BOOST_MATH_CALCULATE_CONSTANTS_CONSTANTS_INCLUDED
#include <boost/static_assert.hpp>
#include <boost/math/special_functions/trunc.hpp>
namespace boost{ namespace math{ namespace constants{ namespace detail{
template <class T>
@@ -808,7 +808,6 @@ T zeta_series_derivative_2(unsigned digits)
// Derivative of the series part, evaluated at 2:
BOOST_MATH_STD_USING
int n = digits * 301 * 13 / 10000;
boost::math::itrunc((std::numeric_limits<T>::digits10 + 1) * 1.3);
T d = pow(3 + sqrt(T(8)), n);
d = (d + 1 / d) / 2;
T b = -1;

View File

@@ -0,0 +1,149 @@
// (C) Copyright Nick Thompson 2020.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <benchmark/benchmark.h>
#include <boost/math/constants/constants.hpp>
#include <boost/multiprecision/mpfr.hpp>
using namespace boost::math::constants;
using boost::multiprecision::mpfr_float;
void Pi(benchmark::State& state)
{
mpfr_float::default_precision(state.range(0));
for (auto _ : state)
{
benchmark::DoNotOptimize(pi<mpfr_float>());
}
state.SetComplexityN(state.range(0));
}
BENCHMARK(Pi)->RangeMultiplier(2)->Range(512, 1<<20)->Complexity()->Unit(benchmark::kMicrosecond);
void Gauss(benchmark::State& state)
{
mpfr_float::default_precision(state.range(0));
for (auto _ : state)
{
benchmark::DoNotOptimize(gauss<mpfr_float>());
}
state.SetComplexityN(state.range(0));
}
BENCHMARK(Gauss)->RangeMultiplier(2)->Range(512, 1<<20)->Complexity()->Unit(benchmark::kMicrosecond);
void Exp1(benchmark::State& state)
{
mpfr_float::default_precision(state.range(0));
for (auto _ : state)
{
benchmark::DoNotOptimize(e<mpfr_float>());
}
state.SetComplexityN(state.range(0));
}
BENCHMARK(Exp1)->RangeMultiplier(2)->Range(512, 1<<20)->Complexity()->Unit(benchmark::kMicrosecond);
void Catalan(benchmark::State& state)
{
mpfr_float::default_precision(state.range(0));
for (auto _ : state)
{
benchmark::DoNotOptimize(catalan<mpfr_float>());
}
state.SetComplexityN(state.range(0));
}
BENCHMARK(Catalan)->RangeMultiplier(2)->Range(512, 1<<20)->Complexity()->Unit(benchmark::kMicrosecond);
void Plastic(benchmark::State& state)
{
mpfr_float::default_precision(state.range(0));
for (auto _ : state)
{
benchmark::DoNotOptimize(plastic<mpfr_float>());
}
state.SetComplexityN(state.range(0));
}
BENCHMARK(Plastic)->RangeMultiplier(2)->Range(512, 1<<20)->Complexity()->Unit(benchmark::kMicrosecond);
void RootTwo(benchmark::State& state)
{
mpfr_float::default_precision(state.range(0));
for (auto _ : state)
{
benchmark::DoNotOptimize(root_two<mpfr_float>());
}
state.SetComplexityN(state.range(0));
}
BENCHMARK(RootTwo)->RangeMultiplier(2)->Range(512, 1<<20)->Complexity()->Unit(benchmark::kMicrosecond);
void ZetaThree(benchmark::State& state)
{
mpfr_float::default_precision(state.range(0));
for (auto _ : state)
{
benchmark::DoNotOptimize(zeta_three<mpfr_float>());
}
state.SetComplexityN(state.range(0));
}
BENCHMARK(ZetaThree)->RangeMultiplier(2)->Range(512, 1<<20)->Complexity()->Unit(benchmark::kMicrosecond);
void Euler(benchmark::State& state)
{
mpfr_float::default_precision(state.range(0));
for (auto _ : state)
{
benchmark::DoNotOptimize(euler<mpfr_float>());
}
state.SetComplexityN(state.range(0));
}
BENCHMARK(Euler)->RangeMultiplier(2)->Range(512, 1<<20)->Complexity()->Unit(benchmark::kMicrosecond);
void LnTwo(benchmark::State& state)
{
mpfr_float::default_precision(state.range(0));
for (auto _ : state)
{
benchmark::DoNotOptimize(ln_two<mpfr_float>());
}
state.SetComplexityN(state.range(0));
}
BENCHMARK(LnTwo)->RangeMultiplier(2)->Range(512, 1<<20)->Complexity()->Unit(benchmark::kMicrosecond);
void Glaisher(benchmark::State& state)
{
mpfr_float::default_precision(state.range(0));
for (auto _ : state)
{
benchmark::DoNotOptimize(glaisher<mpfr_float>());
}
state.SetComplexityN(state.range(0));
}
BENCHMARK(Glaisher)->RangeMultiplier(2)->Range(512, 4096)->Complexity()->Unit(benchmark::kMicrosecond);
void Khinchin(benchmark::State& state)
{
mpfr_float::default_precision(state.range(0));
for (auto _ : state)
{
benchmark::DoNotOptimize(khinchin<mpfr_float>());
}
state.SetComplexityN(state.range(0));
}
// There is a performance bug in the Khinchin constant:
BENCHMARK(Khinchin)->RangeMultiplier(2)->Range(512, 512)->Complexity()->Unit(benchmark::kMicrosecond);
BENCHMARK_MAIN();