Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/m/mo_yanxi-react_flow/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package("mo_yanxi-react_flow")

set_homepage("https://github.com/Yuria-Shikibe/mo_yanxi_react_flow")
set_description("A lightweight, C++23 module-interface-only data graph publisher-receiver framework.")
set_license("MIT")

add_urls(
"https://github.com/Yuria-Shikibe/mo_yanxi_react_flow/archive/refs/tags/$(version).tar.gz",
"https://github.com/Yuria-Shikibe/mo_yanxi_react_flow.git", {
excludes = {"*/properties/*, */test/*, */examples/*, */benchmark/*"}
}
)

add_versions("0.1.0", "EA76859AEB414C124A52EF0B91007E8B0FD2527EF47EC129E12E34041EE049D4")

if is_plat("windows") then
set_policy("platform.longpaths", true)
end

add_includedirs("include")

on_install(function (package)
local configs = {add_test = false, add_benchmark = false}
import("package.tools.xmake").install(package, configs)
end)
83 changes: 83 additions & 0 deletions tests/m/mo_yanxi-react_flow/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <mo_yanxi/adapted_attributes.hpp>

import mo_yanxi.react_flow;
import mo_yanxi.react_flow.common;

import std;

void benchmark_diamond_dag() {
using namespace mo_yanxi::react_flow;
constexpr std::uint32_t iterations = 1'000'000;

// --- 1. React Flow 设置 ---
manager mgr{manager_no_async}; // 禁用异步以单纯测试计算开销

auto& p_a = mgr.add_node<provider_cached<double>>();
auto& p_b = mgr.add_node<provider_cached<double>>();
auto& p_c = mgr.add_node<provider_cached<double>>();

auto& t_x = mgr.add_node(make_transformer([](double a, double b) {
return a + b;
}));
auto& t_y = mgr.add_node(make_transformer([](double b, double c) {
return b * c;
}));
auto& t_z = mgr.add_node(make_transformer([](double x, double y) {
return std::sqrt(x * x + y * y);
}));

// 监听最终结果
volatile double dummy_result = 0.0;
auto& listener = mgr.add_node(make_listener([&](double z) {
dummy_result = z;
}));

// 连接节点 (注意:transformer 的参数顺序对应 slot 的索引)
p_a.connect_successor(0, t_x);
p_b.connect_successor(1, t_x);

p_b.connect_successor(0, t_y);
p_c.connect_successor(1, t_y);

t_x.connect_successor(0, t_z);
t_y.connect_successor(1, t_z);

t_z.connect_successor(0, listener);

// 初始化基础数据
p_a.update_value(10.0);
p_c.update_value(5.0);

// --- 2. Benchmark: Node Flow ---
auto start_node = std::chrono::high_resolution_clock::now();
for (std::uint32_t i = 0; i < iterations; ++i) {
p_b.update_value(static_cast<double>(i)); // 触发整条链路的 update
}
auto end_node = std::chrono::high_resolution_clock::now();

// --- 3. Benchmark: 直接硬编码 ---
auto start_direct = std::chrono::high_resolution_clock::now();
double a = 10.0;
double c = 5.0;
for (std::uint32_t i = 0; i < iterations; ++i) {
double b = static_cast<double>(i);
double x = a + b;
double y = b * c;
dummy_result = std::sqrt(x * x + y * y);
}
auto end_direct = std::chrono::high_resolution_clock::now();

// --- 输出结果 ---
auto duration_node = std::chrono::duration_cast<std::chrono::milliseconds>(end_node - start_node).count();
auto duration_direct = std::chrono::duration_cast<std::chrono::milliseconds>(end_direct - start_direct).count();

std::println("=== Diamond DAG Benchmark ({} iterations) ===", iterations);
std::println("React Flow Duration: {} ms", duration_node);
std::println("Direct Code Duration: {} ms", duration_direct);
std::println("Overhead Ratio: {:.2f}x", static_cast<double>(duration_node) / static_cast<double>(std::max<long long>(duration_direct, 1)));
}


int main(){
benchmark_diamond_dag();
}
8 changes: 8 additions & 0 deletions tests/m/mo_yanxi-react_flow/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
add_requires("mo_yanxi-react_flow 0.1.0")

target("mo_yanxi-react_flow_test")
set_kind("binary")
set_languages("c++23")
add_files("main.cpp")
add_packages("mo_yanxi-react_flow")
set_policy("build.c++.modules", true)
1 change: 1 addition & 0 deletions tests/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ includes("l/lua")
includes("c/cmdline")
includes("t/templates")
includes("m/mcpplibs-xpkg")
includes("m/mo_yanxi-react_flow")