#include "domain/control_logic_model.h" #include "domain/register_repository.h" #include "domain/virtual_register_repository.h" #include "services/software_logic_executor.h" #include #include #include #include #include namespace { LogicNode contact(const std::string &id, int address) { return {id, ContactNodeConfig{ RegisterAddress{RegisterArea::M, address}, ContactMode::NormallyOpen}, true}; } LogicNode coil(const std::string &id, int address) { return {id, CoilNodeConfig{ RegisterAddress{RegisterArea::M, address}, CoilMode::Normal}, true}; } ControlLogic makeLogic(int index) { LadderRung rung; rung.id = "rung-" + std::to_string(index); rung.name = rung.id; for (int column = 0; column < ProjectLimits::kMaximumConditionColumns; ++column) { rung.cells.push_back({ rung.id + "-cell-" + std::to_string(column), column == 0 ? LadderCellKind::Node : LadderCellKind::Wire, column == 0 ? std::optional{contact( "contact-" + std::to_string(index), index)} : std::nullopt}); } rung.output = coil("coil-" + std::to_string(index), index + 100); return {"logic-" + std::to_string(index), "logic-" + std::to_string(index), {rung}, true, {}}; } class PerformanceTests final : public QObject { Q_OBJECT private slots: void initTestCase() { qInfo().noquote() << QStringLiteral("性能测试开始:下面两项 RESULT 的耗时均为平均每次执行时间"); qInfo().noquote() << QStringLiteral("测试项目 1:100 个控制逻辑的软件扫描"); qInfo().noquote() << QStringLiteral("测试项目 2:M0 到 M4000 共 4001 个虚拟 M 地址的完整写入和读取"); } void softwareExecutor_scansRepresentativeProject() { std::vector logics; logics.reserve(100); for (int index = 0; index < 100; ++index) { logics.push_back(makeLogic(index)); } SoftwareLogicExecutor executor; VirtualRegisterRepository repository; QVERIFY(executor.validate(logics).succeeded); QVERIFY(executor.executeScan(logics, repository).succeeded); QBENCHMARK { executor.executeScan(logics, repository); } } void virtualRepository_handlesBoundaryWorkload() { VirtualRegisterRepository repository; for (int index = 0; index <= RegisterAddress::kMaximumIndex; ++index) { QVERIFY(repository.writeBit( {RegisterArea::M, index}, (index % 2) == 0) .succeeded); QVERIFY(repository.readBit({RegisterArea::M, index}).succeeded); } QBENCHMARK { for (int index = 0; index <= RegisterAddress::kMaximumIndex; ++index) { repository.writeBit( {RegisterArea::M, index}, (index % 2) == 0); repository.readBit({RegisterArea::M, index}); } } } void cleanupTestCase() { qInfo().noquote() << QStringLiteral("性能测试结束:请结合上方两项 RESULT 和最后的 Totals 判断结果"); } }; } // namespace QTEST_APPLESS_MAIN(PerformanceTests) #include "performance_tests.moc"