Open 449134904 opened 2 years ago
From wiki page: https://wiki.swoole.com/#/runtime?id=swoole_hook_tcp
Co\run() 是创建了协程容器,go() 是创建协程
$s = microtime(true); run(function () { for($c = 10; $c--;) { print_r($c); echo "\n"; go(function () { print_r(date("Y-m-d H:i:s")); echo "\n"; $swoole_mysql = new MySQL(); $swoole_mysql->connect([ 'host' => '127.0.0.1', 'port' => 3306, 'user' => 'root', 'password' => '123123', 'database' => 'blt_test', ]); $sta = $swoole_mysql->prepare('select * from oscshop_lionfish_comshop_coupon_list limit 1000');
for($n = 100; $n--;) {
// $res = $swoole_mysql->query('select * from oscshop_lionfish_comshop_coupon_list'); // var_dump($res); $res = $sta->execute(); // assert(count($res)>0); if(!assert(count($res) > 0)) { var_dump($res); } // var_dump(assert(count($res)>0)); } }); } }); //Event::wait(); echo '耗时:'.(microtime(true) - $s)."s\n";
我发现去除run耗时更少,请问这有什么区别吗?
From wiki page: https://wiki.swoole.com/#/runtime?id=swoole_hook_tcp
Co\run() 是创建了协程容器,go() 是创建协程
$s = microtime(true); run(function () { for($c = 10; $c--;) { print_r($c); echo "\n"; go(function () { print_r(date("Y-m-d H:i:s")); echo "\n"; $swoole_mysql = new MySQL(); $swoole_mysql->connect([ 'host' => '127.0.0.1', 'port' => 3306, 'user' => 'root', 'password' => '123123', 'database' => 'blt_test', ]); $sta = $swoole_mysql->prepare('select * from oscshop_lionfish_comshop_coupon_list limit 1000');
// $res = $swoole_mysql->query('select * from oscshop_lionfish_comshop_coupon_list'); // var_dump($res); $res = $sta->execute(); // assert(count($res)>0); if(!assert(count($res) > 0)) { var_dump($res); } // var_dump(assert(count($res)>0)); } }); } }); //Event::wait(); echo '耗时:'.(microtime(true) - $s)."s\n";
我发现去除run耗时更少,请问这有什么区别吗?