Files
茂之钳 9bf673e337
CI / Build & Test (push) Failing after 37s
CI / Release Build (push) Failing after 43s
fix: Delaunay3D circumcenter 完整实现 + 测试恢复
2026-07-23 23:22:35 +00:00

78 lines
2.6 KiB
C++

/// bench_curves.cpp — Bezier / BSpline evaluation benchmarks
///
/// Metrics:
/// BezierEval/N{iterations} — evaluate() throughput on a cubic Bezier
/// BSplineEval/N{iterations} — evaluate() throughput on a cubic BSpline
#include <benchmark/benchmark.h>
#include <vde/curves/bezier_curve.h>
#include <vde/curves/bspline_curve.h>
#include <vde/core/point.h>
#include <random>
#include <vector>
using namespace vde;
namespace {
/// A cubic Bezier with control points scattered in [-10, 10]³
curves::BezierCurve sample_bezier() {
static std::vector<core::Point3D> cp = {
{0.0, 0.0, 0.0}, {3.0, 5.0, -1.0}, {7.0, -2.0, 4.0}, {10.0, 3.0, 2.0}};
return curves::BezierCurve(cp);
}
/// A cubic uniform BSpline with 7 control points
curves::BSplineCurve sample_bspline() {
static std::vector<core::Point3D> cp = {
{0.0, 0.0, 0.0}, {2.0, 4.0, -1.0}, {5.0, 1.0, 3.0},
{8.0, -1.0, 1.0}, {11.0, 3.0, -2.0}, {13.0, 2.0, 0.0}, {15.0, 0.0, 1.0}};
static std::vector<double> knots = {0,0,0,0, 0.25, 0.5, 0.75, 1,1,1,1};
return curves::BSplineCurve(cp, knots, 3);
}
/// N equally spaced t values in [0, 1]
std::vector<double> sample_params(int n) {
std::vector<double> t;
t.reserve(n);
for (int i = 0; i < n; ++i)
t.push_back(static_cast<double>(i) / (n - 1));
return t;
}
} // namespace
// ── Bezier ────────────────────────────────────────────────────────────
static void BezierEval(benchmark::State& state) {
auto curve = sample_bezier();
auto params = sample_params(state.range(0));
double sum = 0;
for (auto _ : state) {
for (double t : params) {
auto p = curve.evaluate(t);
benchmark::DoNotOptimize(sum += p.x());
}
}
benchmark::DoNotOptimize(sum);
state.SetItemsProcessed(state.iterations() * params.size());
}
BENCHMARK(BezierEval)->Arg(10000)->Arg(100000);
// ── BSpline ───────────────────────────────────────────────────────────
static void BSplineEval(benchmark::State& state) {
auto curve = sample_bspline();
auto params = sample_params(state.range(0));
double sum = 0;
for (auto _ : state) {
for (double t : params) {
auto p = curve.evaluate(t);
benchmark::DoNotOptimize(sum += p.x());
}
}
benchmark::DoNotOptimize(sum);
state.SetItemsProcessed(state.iterations() * params.size());
}
BENCHMARK(BSplineEval)->Arg(10000)->Arg(100000);