Skip to content
This repository was archived by the owner on Aug 18, 2025. It is now read-only.

Commit b575b5c

Browse files
committed
新增条件表达式JIT编译专项测试,涵盖简单、复合、多重、数学、模运算、嵌套及复杂逻辑条件,验证优化效果并提升条件判断性能。
1 parent 90b44fc commit b575b5c

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed

conditional_expressions_test.cn

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// 🚀 CodeNothing v0.6.6 条件表达式JIT编译专项测试
2+
// 验证if语句中复杂条件判断的JIT编译优化
3+
4+
using lib <io>;
5+
using ns std;
6+
7+
fn main() : int {
8+
std::println("🚀 CodeNothing v0.6.6 条件表达式JIT编译专项测试");
9+
std::println("=====================================");
10+
11+
// 📊 测试1:简单条件表达式测试
12+
std::println("🎯 测试1:简单条件表达式优化");
13+
simple_count : int = 0;
14+
for (i : 1..201) { // 200次迭代,触发JIT编译
15+
if (i > 50) {
16+
simple_count = simple_count + 1;
17+
};
18+
};
19+
std::println("简单条件匹配: " + simple_count);
20+
std::println("-------------------------------------");
21+
22+
// 📊 测试2:复合条件表达式测试
23+
std::println("🔧 测试2:复合条件表达式优化");
24+
compound_count : int = 0;
25+
for (i : 1..201) { // 200次迭代
26+
if (i > 25 && i < 175) {
27+
compound_count = compound_count + 1;
28+
};
29+
};
30+
std::println("复合条件匹配: " + compound_count);
31+
std::println("-------------------------------------");
32+
33+
// 📊 测试3:多重条件分支测试
34+
std::println("🎨 测试3:多重条件分支优化");
35+
branch_count_1 : int = 0;
36+
branch_count_2 : int = 0;
37+
branch_count_3 : int = 0;
38+
for (i : 1..201) { // 200次迭代
39+
if (i <= 50) {
40+
branch_count_1 = branch_count_1 + 1;
41+
};
42+
if (i > 50 && i <= 150) {
43+
branch_count_2 = branch_count_2 + 1;
44+
};
45+
if (i > 150) {
46+
branch_count_3 = branch_count_3 + 1;
47+
};
48+
};
49+
std::println("分支1匹配: " + branch_count_1);
50+
std::println("分支2匹配: " + branch_count_2);
51+
std::println("分支3匹配: " + branch_count_3);
52+
std::println("-------------------------------------");
53+
54+
// 📊 测试4:数学条件表达式测试
55+
std::println("📊 测试4:数学条件表达式优化");
56+
math_count : int = 0;
57+
for (i : 1..201) { // 200次迭代
58+
result : int = i * i;
59+
if (result > 100 && result < 10000) {
60+
math_count = math_count + 1;
61+
};
62+
};
63+
std::println("数学条件匹配: " + math_count);
64+
std::println("-------------------------------------");
65+
66+
// 📊 测试5:模运算条件测试
67+
std::println("🔢 测试5:模运算条件优化");
68+
mod_count : int = 0;
69+
for (i : 1..201) { // 200次迭代
70+
if (i % 3 == 0 || i % 5 == 0) {
71+
mod_count = mod_count + 1;
72+
};
73+
};
74+
std::println("模运算条件匹配: " + mod_count);
75+
std::println("-------------------------------------");
76+
77+
// 📊 测试6:嵌套条件表达式测试
78+
std::println("🎭 测试6:嵌套条件表达式优化");
79+
nested_count : int = 0;
80+
for (i : 1..201) { // 200次迭代
81+
if (i > 10) {
82+
if (i < 190) {
83+
if (i % 2 == 0) {
84+
nested_count = nested_count + 1;
85+
};
86+
};
87+
};
88+
};
89+
std::println("嵌套条件匹配: " + nested_count);
90+
std::println("-------------------------------------");
91+
92+
// 📊 测试7:复杂逻辑条件组合测试
93+
std::println("⚡ 测试7:复杂逻辑条件组合优化");
94+
complex_count : int = 0;
95+
for (i : 1..201) { // 200次迭代
96+
x : int = i + 5;
97+
y : int = i * 2;
98+
z : int = i - 3;
99+
100+
if ((x > y || y > z) && (x < 100 || z > 0)) {
101+
complex_count = complex_count + 1;
102+
};
103+
};
104+
std::println("复杂逻辑条件匹配: " + complex_count);
105+
std::println("-------------------------------------");
106+
107+
// 📊 测试8:条件表达式性能基准测试
108+
std::println("🚀 测试8:条件表达式性能基准");
109+
performance_count : int = 0;
110+
for (i : 1..1001) { // 1000次迭代,高强度测试
111+
a : int = i % 7;
112+
b : int = i % 11;
113+
c : int = i % 13;
114+
115+
if ((a == 0 && b != 0) || (b == 0 && c != 0) || (c == 0 && a != 0)) {
116+
performance_count = performance_count + 1;
117+
};
118+
};
119+
std::println("性能基准测试匹配: " + performance_count);
120+
std::println("=====================================");
121+
122+
std::println("🎉 条件表达式JIT编译专项测试完成!");
123+
std::println("请查看JIT统计信息验证优化效果");
124+
125+
return 0;
126+
};

0 commit comments

Comments
 (0)