2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00
Files
math/reporting/performance/bezier_polynomial_performance.cpp
Nick af14cdaf47 Bezier polynomials. (#650)
* Bezier polynomials.

* Bezier polynomials.

* Performance test.

* Implement de Casteljau's algorithm.

* Documentation and cleanup.

* Use thread_local storage to increase performance of interpolation.

* Inspect tool doesn't like asserts or anonymous namespaces.

* Test convex hull property of Bezier polynomial and add float128 tests.

* Allow editing of control points.

* Add .prime member function. Fix bug when scratch space size is larger than control point size. Document alternative implementations found in Bezier and B-spline techniques.

* Submit failing unit test so I don't forget to fix it later

* Add indefinite integral and tests.

* Do not test on gcc < 9 on MingW.
2021-07-01 19:31:51 -04:00

43 lines
1.1 KiB
C++

// (C) Copyright Nick Thompson 2021.
// 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 <array>
#include <vector>
#include <benchmark/benchmark.h>
#include <boost/math/interpolators/bezier_polynomial.hpp>
using boost::math::interpolators::bezier_polynomial;
template<class Real>
void BezierPolynomial(benchmark::State& state)
{
std::random_device rd;
std::mt19937_64 mt(rd());
std::uniform_real_distribution<Real> unif(0, 10);
std::vector<std::array<Real, 3>> v(state.range(0));
for (size_t i = 0; i < v.size(); ++i) {
v[i][0] = unif(mt);
v[i][1] = unif(mt);
v[i][2] = unif(mt);
}
auto bp = bezier_polynomial(std::move(v));
Real t = 0;
for (auto _ : state)
{
auto p = bp(t);
benchmark::DoNotOptimize(p[0]);
t += std::numeric_limits<Real>::epsilon();
}
state.SetComplexityN(state.range(0));
}
BENCHMARK_TEMPLATE(BezierPolynomial, double)->DenseRange(2, 30)->Complexity();
BENCHMARK_MAIN();