|
| 1 | +// 🚀 CodeNothing v0.6.6 逻辑运算符JIT编译专项测试 |
| 2 | +// 验证逻辑运算符的短路求值和性能优化 |
| 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 | + and_true_count : int = 0; |
| 14 | + and_false_count : int = 0; |
| 15 | + for (i : 1..151) { // 150次迭代,触发JIT编译 |
| 16 | + // 第一个条件为true,需要计算第二个条件 |
| 17 | + if (i > 0 && i < 100) { |
| 18 | + and_true_count = and_true_count + 1; |
| 19 | + }; |
| 20 | + // 第一个条件为false,应该短路,不计算第二个条件 |
| 21 | + if (i < 0 && i > 100) { |
| 22 | + and_false_count = and_false_count + 1; |
| 23 | + }; |
| 24 | + }; |
| 25 | + std::println("逻辑与true分支: " + and_true_count); |
| 26 | + std::println("逻辑与false分支: " + and_false_count); |
| 27 | + std::println("-------------------------------------"); |
| 28 | + |
| 29 | + // 📊 测试2:逻辑或(||)短路求值测试 |
| 30 | + std::println("⚡ 测试2:逻辑或短路求值优化"); |
| 31 | + or_true_count : int = 0; |
| 32 | + or_false_count : int = 0; |
| 33 | + for (i : 1..151) { // 150次迭代 |
| 34 | + // 第一个条件为true,应该短路,不计算第二个条件 |
| 35 | + if (i > 0 || i < 0) { |
| 36 | + or_true_count = or_true_count + 1; |
| 37 | + }; |
| 38 | + // 第一个条件为false,需要计算第二个条件 |
| 39 | + if (i < 0 || i > 100) { |
| 40 | + or_false_count = or_false_count + 1; |
| 41 | + }; |
| 42 | + }; |
| 43 | + std::println("逻辑或true分支: " + or_true_count); |
| 44 | + std::println("逻辑或false分支: " + or_false_count); |
| 45 | + std::println("-------------------------------------"); |
| 46 | + |
| 47 | + // 📊 测试3:逻辑非(!)运算测试 |
| 48 | + std::println("🔄 测试3:逻辑非运算优化"); |
| 49 | + not_true_count : int = 0; |
| 50 | + not_false_count : int = 0; |
| 51 | + for (i : 1..151) { // 150次迭代 |
| 52 | + // 逻辑非测试 |
| 53 | + condition : int = i % 2; // 0或1 |
| 54 | + if (condition == 0) { |
| 55 | + not_true_count = not_true_count + 1; |
| 56 | + }; |
| 57 | + if (i <= 75) { |
| 58 | + not_false_count = not_false_count + 1; |
| 59 | + }; |
| 60 | + }; |
| 61 | + std::println("逻辑非true计数: " + not_true_count); |
| 62 | + std::println("逻辑非false计数: " + not_false_count); |
| 63 | + std::println("-------------------------------------"); |
| 64 | + |
| 65 | + // 📊 测试4:复杂逻辑表达式组合测试 |
| 66 | + std::println("🎯 测试4:复杂逻辑表达式优化"); |
| 67 | + complex_logic_count : int = 0; |
| 68 | + for (i : 1..151) { // 150次迭代 |
| 69 | + // 复杂逻辑组合:(A && B) || (C && D) |
| 70 | + if ((i > 25 && i < 125) || (i % 3 == 0 && i % 5 == 0)) { |
| 71 | + complex_logic_count = complex_logic_count + 1; |
| 72 | + }; |
| 73 | + }; |
| 74 | + std::println("复杂逻辑表达式匹配: " + complex_logic_count); |
| 75 | + std::println("-------------------------------------"); |
| 76 | + |
| 77 | + // 📊 测试5:嵌套逻辑运算测试 |
| 78 | + std::println("🔧 测试5:嵌套逻辑运算优化"); |
| 79 | + nested_logic_count : int = 0; |
| 80 | + for (i : 1..151) { // 150次迭代 |
| 81 | + // 嵌套逻辑:简化版本 |
| 82 | + if ((i >= 50 || i <= 25) || (i % 7 == 0 || i % 11 == 0)) { |
| 83 | + nested_logic_count = nested_logic_count + 1; |
| 84 | + }; |
| 85 | + }; |
| 86 | + std::println("嵌套逻辑表达式匹配: " + nested_logic_count); |
| 87 | + std::println("-------------------------------------"); |
| 88 | + |
| 89 | + // 📊 测试6:逻辑运算性能基准测试 |
| 90 | + std::println("📊 测试6:逻辑运算性能基准"); |
| 91 | + performance_count : int = 0; |
| 92 | + for (i : 1..1001) { // 1000次迭代,高强度测试 |
| 93 | + // 多重逻辑条件 |
| 94 | + if ((i > 100 && i < 900) || (i % 13 == 0) || (i % 17 == 0)) { |
| 95 | + if ((i % 2 != 0) || (i % 3 != 0)) { |
| 96 | + performance_count = performance_count + 1; |
| 97 | + }; |
| 98 | + }; |
| 99 | + }; |
| 100 | + std::println("性能基准测试匹配: " + performance_count); |
| 101 | + std::println("-------------------------------------"); |
| 102 | + |
| 103 | + // 📊 测试7:逻辑运算与比较运算组合 |
| 104 | + std::println("🎨 测试7:逻辑比较组合优化"); |
| 105 | + combo_count : int = 0; |
| 106 | + for (i : 1..151) { // 150次迭代 |
| 107 | + x : int = i * 2; |
| 108 | + y : int = i + 10; |
| 109 | + z : int = i - 5; |
| 110 | + |
| 111 | + // 逻辑运算与比较运算的复杂组合 |
| 112 | + if ((x > y && y > z) || (x == y || z < 0)) { |
| 113 | + combo_count = combo_count + 1; |
| 114 | + }; |
| 115 | + }; |
| 116 | + std::println("逻辑比较组合匹配: " + combo_count); |
| 117 | + std::println("====================================="); |
| 118 | + |
| 119 | + std::println("🎉 逻辑运算符JIT编译专项测试完成!"); |
| 120 | + std::println("请查看JIT统计信息验证优化效果"); |
| 121 | + |
| 122 | + return 0; |
| 123 | +}; |
0 commit comments