From 15f9d35c696c22d6382f9e4274dbfb9e66529586 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 28 Apr 2026 19:30:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor(examples):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=9F=BA=E5=87=86=E6=B5=8B=E8=AF=95=E5=92=8C=E5=8D=8F=E7=A8=8B?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 simplecall 函数中添加计算总和并打印结果 - 统一函数定义的大括号格式 - 修复 matrix 和 sieve 函数的参数类型声明 - 调整 return 语句的括号格式 - 使用 Swoole\Coroutine\run 函数别名简化调用 --- examples/bench.php | 15 +++++++++------ examples/swoole/co.php | 3 ++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/examples/bench.php b/examples/bench.php index 8c12e039..acdf8a04 100644 --- a/examples/bench.php +++ b/examples/bench.php @@ -19,9 +19,12 @@ function simple() /****/ -function simplecall() { - for ($i = 0; $i < 1000000; $i++) - strlen("hallo" . $i); +function simplecall() +{ + $total = 0; + for ($i = 0; $i < 1000000; $i++) + $total += strlen("hallo" . $i); + print "$total\n"; } /****/ @@ -277,7 +280,7 @@ function mkmatrix ($rows, $cols) { $mx[$i][$j] = $count++; } } - return($mx); + return ($mx); } function mmult ($rows, $cols, $m1, $m2) { @@ -294,7 +297,7 @@ function mmult ($rows, $cols, $m1, $m2) { return($m3); } -function matrix($n) { +function matrix(int $n) { $SIZE = 30; $m1 = mkmatrix($SIZE, $SIZE); $m2 = mkmatrix($SIZE, $SIZE); @@ -320,7 +323,7 @@ function nestedloop($n) { /****/ -function sieve($n) { +function sieve(int $n) { $count = 0; while ($n-- > 0) { $count = 0; diff --git a/examples/swoole/co.php b/examples/swoole/co.php index c6bc5d9c..720d8d47 100644 --- a/examples/swoole/co.php +++ b/examples/swoole/co.php @@ -1,8 +1,9 @@