2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00
Files
math/reporting/performance/logaddexp_performance.cpp
Matt Borland e8c40e309c Implement logaddexp (#763)
* Implement logaddexp

* Disable test for ASAN

* Implement logsumexp

* Add performance file and include results in the docs

* Address review comments

* Simplify overflow test and comply with min/max guidelines

* Minor cleanup

* FIxes to comments and docs [ci skip]

* Return status code.

Co-authored-by: Nick Thompson <nathompson7@protonmail.com>
2022-02-24 07:55:25 -08:00

36 lines
1.0 KiB
C++

// (C) Copyright Matt Borland 2022.
// 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 <random>
#include <limits>
#include <benchmark/benchmark.h>
#include <boost/math/special_functions/logaddexp.hpp>
using boost::math::logaddexp;
template <typename Real>
void logaddexp_performance(benchmark::State& state)
{
std::random_device rd;
std::mt19937_64 mt {rd()};
std::uniform_real_distribution<long double> dist(1e-50, 5e-50);
Real x = static_cast<Real>(dist(mt));
Real y = static_cast<Real>(dist(mt));
for (auto _ : state)
{
benchmark::DoNotOptimize(logaddexp(x, y));
x += std::numeric_limits<Real>::epsilon();
y += std::numeric_limits<Real>::epsilon();
}
}
BENCHMARK_TEMPLATE(logaddexp_performance, float);
BENCHMARK_TEMPLATE(logaddexp_performance, double);
BENCHMARK_TEMPLATE(logaddexp_performance, long double);
BENCHMARK_MAIN();