refactor(examples): 优化基准测试和协程示例代码

- 在 simplecall 函数中添加计算总和并打印结果
- 统一函数定义的大括号格式
- 修复 matrix 和 sieve 函数的参数类型声明
- 调整 return 语句的括号格式
- 使用 Swoole\Coroutine\run 函数别名简化调用
pull/1/head
韩天峰 4 months ago
parent 7f260f3d52
commit 15f9d35c69
  1. 15
      examples/bench.php
  2. 3
      examples/swoole/co.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;

@ -1,8 +1,9 @@
<?php
use function Swoole\Coroutine\run;
function main(): void
{
Swoole\Coroutine\run(function () {
run(function () {
sleep(1);
});
}
Loading…
Cancel
Save