36 lines
989 B
C++
36 lines
989 B
C++
/// bench_delaunay.cpp — 2D Delaunay triangulation benchmarks
|
|
///
|
|
/// Metrics:
|
|
/// Delaunay2D/N{size} — Bowyer-Watson triangulation time for N random points
|
|
|
|
#include <benchmark/benchmark.h>
|
|
#include <vde/mesh/delaunay_2d.h>
|
|
#include <random>
|
|
#include <vector>
|
|
|
|
using namespace vde;
|
|
|
|
namespace {
|
|
|
|
std::vector<core::Point2D> random_points_2d(int n, double R = 1000.0) {
|
|
std::mt19937 rng(42);
|
|
std::uniform_real_distribution<double> dist(-R, R);
|
|
std::vector<core::Point2D> pts;
|
|
pts.reserve(n);
|
|
for (int i = 0; i < n; ++i)
|
|
pts.emplace_back(dist(rng), dist(rng));
|
|
return pts;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
static void Delaunay2D(benchmark::State& state) {
|
|
auto pts = random_points_2d(state.range(0));
|
|
for (auto _ : state) {
|
|
auto result = mesh::delaunay_2d(pts);
|
|
benchmark::DoNotOptimize(result.triangles.size());
|
|
}
|
|
state.SetItemsProcessed(state.iterations() * state.range(0));
|
|
}
|
|
BENCHMARK(Delaunay2D)->Arg(100)->Arg(1000)->Arg(10000);
|