Skip to content

Commit cb789a0

Browse files
committed
Add package mo_yanxi-react_flow to indices
1 parent 56ac85e commit cb789a0

File tree

4 files changed

+117
-0
lines changed

4 files changed

+117
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package("mo_yanxi-react_flow")
2+
3+
set_homepage("https://github.com/Yuria-Shikibe/mo_yanxi_react_flow")
4+
set_description("A lightweight, C++23 module-interface-only data graph publisher-receiver framework.")
5+
set_license("MIT")
6+
7+
add_urls(
8+
"https://github.com/Yuria-Shikibe/mo_yanxi_react_flow/archive/refs/tags/$(version).tar.gz",
9+
"https://github.com/Yuria-Shikibe/mo_yanxi_react_flow.git", {
10+
excludes = {"*/properties/*"}
11+
}
12+
)
13+
14+
add_versions("0.1.0", "EA76859AEB414C124A52EF0B91007E8B0FD2527EF47EC129E12E34041EE049D4")
15+
16+
if is_plat("windows") then
17+
set_policy("platform.longpaths", true)
18+
end
19+
20+
add_includedirs("include")
21+
22+
on_install(function (package)
23+
local configs = {add_test = false, add_benchmark = false}
24+
import("package.tools.xmake").install(package, configs)
25+
end)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include <mo_yanxi/adapted_attributes.hpp>
2+
3+
import mo_yanxi.react_flow;
4+
import mo_yanxi.react_flow.common;
5+
6+
import std;
7+
8+
void benchmark_diamond_dag() {
9+
using namespace mo_yanxi::react_flow;
10+
constexpr std::uint32_t iterations = 1'000'000;
11+
12+
// --- 1. React Flow 设置 ---
13+
manager mgr{manager_no_async}; // 禁用异步以单纯测试计算开销
14+
15+
auto& p_a = mgr.add_node<provider_cached<double>>();
16+
auto& p_b = mgr.add_node<provider_cached<double>>();
17+
auto& p_c = mgr.add_node<provider_cached<double>>();
18+
19+
auto& t_x = mgr.add_node(make_transformer([](double a, double b) {
20+
return a + b;
21+
}));
22+
auto& t_y = mgr.add_node(make_transformer([](double b, double c) {
23+
return b * c;
24+
}));
25+
auto& t_z = mgr.add_node(make_transformer([](double x, double y) {
26+
return std::sqrt(x * x + y * y);
27+
}));
28+
29+
// 监听最终结果
30+
volatile double dummy_result = 0.0;
31+
auto& listener = mgr.add_node(make_listener([&](double z) {
32+
dummy_result = z;
33+
}));
34+
35+
// 连接节点 (注意:transformer 的参数顺序对应 slot 的索引)
36+
p_a.connect_successor(0, t_x);
37+
p_b.connect_successor(1, t_x);
38+
39+
p_b.connect_successor(0, t_y);
40+
p_c.connect_successor(1, t_y);
41+
42+
t_x.connect_successor(0, t_z);
43+
t_y.connect_successor(1, t_z);
44+
45+
t_z.connect_successor(0, listener);
46+
47+
// 初始化基础数据
48+
p_a.update_value(10.0);
49+
p_c.update_value(5.0);
50+
51+
// --- 2. Benchmark: Node Flow ---
52+
auto start_node = std::chrono::high_resolution_clock::now();
53+
for (std::uint32_t i = 0; i < iterations; ++i) {
54+
p_b.update_value(static_cast<double>(i)); // 触发整条链路的 update
55+
}
56+
auto end_node = std::chrono::high_resolution_clock::now();
57+
58+
// --- 3. Benchmark: 直接硬编码 ---
59+
auto start_direct = std::chrono::high_resolution_clock::now();
60+
double a = 10.0;
61+
double c = 5.0;
62+
for (std::uint32_t i = 0; i < iterations; ++i) {
63+
double b = static_cast<double>(i);
64+
double x = a + b;
65+
double y = b * c;
66+
dummy_result = std::sqrt(x * x + y * y);
67+
}
68+
auto end_direct = std::chrono::high_resolution_clock::now();
69+
70+
// --- 输出结果 ---
71+
auto duration_node = std::chrono::duration_cast<std::chrono::milliseconds>(end_node - start_node).count();
72+
auto duration_direct = std::chrono::duration_cast<std::chrono::milliseconds>(end_direct - start_direct).count();
73+
74+
std::println("=== Diamond DAG Benchmark ({} iterations) ===", iterations);
75+
std::println("React Flow Duration: {} ms", duration_node);
76+
std::println("Direct Code Duration: {} ms", duration_direct);
77+
std::println("Overhead Ratio: {:.2f}x", static_cast<double>(duration_node) / static_cast<double>(std::max<long long>(duration_direct, 1)));
78+
}
79+
80+
81+
int main(){
82+
benchmark_diamond_dag();
83+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_requires("mo_yanxi-react_flow 0.1.0")
2+
3+
target("mo_yanxi-react_flow_test")
4+
set_kind("binary")
5+
set_languages("c++23")
6+
add_files("main.cpp")
7+
add_packages("mo_yanxi-react_flow")
8+
set_policy("build.c++.modules", true)

tests/xmake.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ includes("l/lua")
55
includes("c/cmdline")
66
includes("t/templates")
77
includes("m/mcpplibs-xpkg")
8+
includes("m/mo_yanxi-react_flow")

0 commit comments

Comments
 (0)