129 lines
4.5 KiB
C++
129 lines
4.5 KiB
C++
/// @file bench_large_file.cpp
|
||
/// @brief Wave3-C4:大文件三段端到端基线(STEP 导入 / automatic_heal / GLB 导出)
|
||
///
|
||
/// 与 docs/reference/32 的 1.9MB / 4941 面历史基线对齐的自动化替代:
|
||
/// 合成 40 × sphere(16,8) = 5120 面 / 9.32MB STEP(引擎自身 export_step 生成),
|
||
/// 分别测量 import(parse+convert)/ automatic_heal / write_brep_gltf(res=32),
|
||
/// 输出 `[BENCH]` 行供 tools/bench/run_bench.ps1 解析入基线/门禁。
|
||
///
|
||
/// 说明:夹具在测试进程内即时生成(约 0.3s),不计入三段耗时;导出文件写到
|
||
/// 系统临时目录并在测试结束删除(不污染仓库/构建目录)。
|
||
#include <gtest/gtest.h>
|
||
|
||
#include <chrono>
|
||
#include <cmath>
|
||
#include <cstdio>
|
||
#include "vde/fs_compat.h"
|
||
#include <string>
|
||
#include <vector>
|
||
|
||
#include "vde/brep/brep.h"
|
||
#include "vde/brep/brep_heal.h"
|
||
#include "vde/brep/brep_validate.h"
|
||
#include "vde/brep/modeling.h"
|
||
#include "vde/brep/step_export.h"
|
||
#include "vde/brep/step_import.h"
|
||
#include "vde/foundation/io_gltf.h"
|
||
|
||
namespace {
|
||
|
||
using Clock = std::chrono::steady_clock;
|
||
|
||
double measure_ms(const std::function<void()>& fn, int iters = 2) {
|
||
double best = 1e18;
|
||
for (int i = 0; i < iters; ++i) {
|
||
const auto t0 = Clock::now();
|
||
fn();
|
||
const double ms =
|
||
std::chrono::duration<double, std::milli>(Clock::now() - t0).count();
|
||
if (ms < best) best = ms;
|
||
}
|
||
return best;
|
||
}
|
||
|
||
void report_bench(const std::string& name, double ms, const std::string& detail) {
|
||
std::printf("[BENCH] %-40s %10.2f ms (%s)\n", name.c_str(), ms, detail.c_str());
|
||
std::fflush(stdout);
|
||
}
|
||
|
||
std::vector<vde::brep::BrepModel> make_large_fixture() {
|
||
std::vector<vde::brep::BrepModel> bodies;
|
||
bodies.reserve(40);
|
||
for (int i = 0; i < 40; ++i) {
|
||
bodies.push_back(vde::brep::make_sphere(5.0, 16, 8));
|
||
bodies.back().set_body_name(0, "sph_" + std::to_string(i));
|
||
}
|
||
return bodies;
|
||
}
|
||
|
||
std::string temp_glb_path() {
|
||
namespace fs = vde::fs;
|
||
std::error_code ec;
|
||
const fs::path dir = fs::temp_directory_path(ec);
|
||
static int idx = 0;
|
||
return (dir / ("vde_bench_large_" + std::to_string(++idx) + ".glb")).string();
|
||
}
|
||
|
||
} // namespace
|
||
|
||
TEST(BenchmarkLargeFile, Import_9MB_5120Faces) {
|
||
const std::string step = vde::brep::export_step(make_large_fixture());
|
||
ASSERT_GT(step.size(), 5u * 1024u * 1024u);
|
||
size_t bodies = 0, faces = 0;
|
||
const double ms = measure_ms([&] {
|
||
const auto imported = vde::brep::import_step_from_string(step);
|
||
bodies = imported.size();
|
||
faces = 0;
|
||
for (const auto& b : imported) faces += b.num_faces();
|
||
});
|
||
ASSERT_EQ(bodies, 40u);
|
||
ASSERT_EQ(faces, 5120u);
|
||
char detail[128];
|
||
std::snprintf(detail, sizeof(detail), "size=%.2fMB bodies=%zu faces=%zu",
|
||
static_cast<double>(step.size()) / (1024.0 * 1024.0), bodies, faces);
|
||
report_bench("LargeFile.Import_9MB", ms, detail);
|
||
EXPECT_LT(ms, 5000.0); // 宽松上限(门禁脚本用更紧的阈值)
|
||
}
|
||
|
||
TEST(BenchmarkLargeFile, Heal_Sphere544Faces) {
|
||
double ms = 0.0;
|
||
size_t faces = 0;
|
||
bool ok = false;
|
||
ms = measure_ms([&] {
|
||
auto body = vde::brep::make_sphere(5.0, 32, 17);
|
||
faces = body.num_faces();
|
||
vde::brep::automatic_heal(body);
|
||
ok = vde::brep::validate(body).valid;
|
||
});
|
||
ASSERT_TRUE(ok);
|
||
ASSERT_EQ(faces, 544u);
|
||
char detail[80];
|
||
std::snprintf(detail, sizeof(detail), "faces=%zu valid=1", faces);
|
||
report_bench("LargeFile.Heal_Sphere544", ms, detail);
|
||
// VDE-1298:-j8 全量并行时墙钟受 CPU 争用影响(曾出现 2.85s > 2.0s),
|
||
// 空载通常 <1s;这里放宽 CTest 门禁阈值,性能回归仍由 run_bench 脚本
|
||
// 在空载环境用更紧的基线判定。
|
||
EXPECT_LT(ms, 4000.0);
|
||
}
|
||
|
||
TEST(BenchmarkLargeFile, ExportGLB_Res32) {
|
||
const vde::brep::BrepModel body = vde::brep::make_sphere(5.0, 32, 17);
|
||
const std::string path = temp_glb_path();
|
||
vde::foundation::GltfExportOptions opts;
|
||
opts.tessellation_res = 32;
|
||
bool ok = false;
|
||
const double ms = measure_ms([&] {
|
||
ok = vde::foundation::write_brep_gltf(path, body, opts);
|
||
});
|
||
ASSERT_TRUE(ok);
|
||
std::error_code ec;
|
||
const auto bytes = vde::fs::file_size(path, ec);
|
||
ASSERT_FALSE(ec);
|
||
vde::fs::remove(path, ec);
|
||
char detail[96];
|
||
std::snprintf(detail, sizeof(detail), "faces=%zu res=32 size=%.2fMB",
|
||
body.num_faces(), static_cast<double>(bytes) / (1024.0 * 1024.0));
|
||
report_bench("LargeFile.ExportGLB_Res32", ms, detail);
|
||
EXPECT_LT(ms, 8000.0);
|
||
}
|