首页
导航
博客
电子书
算法
众创
代码
随贴
关于我们
您好,欢迎来到码863代码分享网! 请
[登录]
/
[注册]
搜 索
标题:
*
140
字
TAG标签:
(用空格隔开)
30
字
恢复历史版本:
请选择分类
html
python
javascript
php
sql
c
c++
c#
java
plain
所有人可见
仅自己可见
编辑器:UEditor
编辑器:TinyMCE
编辑器:Editor.md
HTML转MD
HTML转MD2
<p style="box-sizing: inherit; margin-top: 0px; margin-bottom: 20px; line-height: inherit; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">之前总有人问我 Hprose 快,还是 Yar 快。这个问题我之前的回答都是,我没有做过测试,但我觉得 Yar 应该更快一些,毕竟他是鸟哥完全用纯 C 实现的。但这个答案好像并不能让大多数人满意。所以在被多人多次询问之后,昨晚我终于没忍住测试了一下,但是结果所反映出的并不是 Hprose 快,还是 Yar 快的问题。测试结果所能确定的问题只有一个,那就是在 Swoole 下跑的 Hprose 比在 Web 服务器上跑(比如 php-fpm 方式)更快。</p><p style="box-sizing: inherit; margin-top: 0px; margin-bottom: 20px; line-height: inherit; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">下面我们先来列一下测试程序。</p><h3 style="box-sizing: inherit; font-family: "PingFang SC", "Helvetica Neue", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", Sathu, EucrosiaUPC, Arial, Helvetica, sans-serif; line-height: 1.8; margin: 22px 0px 16px; padding: 0px; font-size: 22px; border: none; color: rgb(51, 51, 51); white-space: normal; background-color: rgb(255, 255, 255);">公共 API</h3><p style="box-sizing: inherit; margin-top: 0px; margin-bottom: 20px; line-height: inherit; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"><span style="box-sizing: inherit; font-weight: 700;">api.php</span></p><pre class="hljs xml" style="box-sizing: border-box; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 13px; word-break: break-word; overflow-wrap: normal; overflow: auto; position: relative; margin-top: 0px; margin-bottom: 20px; padding: 1em; border: none; border-radius: 4px; line-height: 1.5; background-color: rgb(246, 246, 246); color: rgb(51, 51, 51);"><?phpdefine("SEX_UNKNOWN", 0); define("SEX_MALE", 1); define("SEX_FEMALE", 2); define("SEX_INTERSEX", 3);class User { var $name; var $sex; var $birthday; var $age; var $married; function __constructor() {} static function newUser($name, $sex, $birthday, $age, $married) { $user = new self(); $user->name = $name; $user->sex = $sex; $user->birthday = $birthday; $user->age = $age; $user->married = $married; return $user; } }class API { public function hello($name) { return "hello " . $name . "!"; } public function getUserList() { $userlist = array( User::newUser("Amy", SEX_FEMALE, new DateTime("1983-12-03"), 26, true), User::newUser("Bob", SEX_MALE, new DateTime("1989-06-12"), 20, false), User::newUser("Chris", SEX_UNKNOWN, new DateTime("1980-03-08"), 29, true), User::newUser("Alex", SEX_INTERSEX, new DateTime("1992-06-14"), 17, false) ); return $userlist; } }</pre><h3 style="box-sizing: inherit; font-family: "PingFang SC", "Helvetica Neue", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", Sathu, EucrosiaUPC, Arial, Helvetica, sans-serif; line-height: 1.8; margin: 22px 0px 16px; padding: 0px; font-size: 22px; border: none; color: rgb(51, 51, 51); white-space: normal; background-color: rgb(255, 255, 255);">Hprose HTTP 服务器和客户端</h3><p style="box-sizing: inherit; margin-top: 0px; margin-bottom: 20px; line-height: inherit; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"><span style="box-sizing: inherit; font-weight: 700;">hprose_server.php</span></p><pre class="hljs xml" style="box-sizing: border-box; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 13px; word-break: break-word; overflow-wrap: normal; overflow: auto; position: relative; margin-top: 0px; margin-bottom: 20px; padding: 1em; border: none; border-radius: 4px; line-height: 1.5; background-color: rgb(246, 246, 246); color: rgb(51, 51, 51);"><?phpinclude("Hprose.php");include("api.php"); $server = new HproseHttpServer(); $server->addInstanceMethods(new API()); $server->start();</pre><p style="box-sizing: inherit; margin-top: 0px; margin-bottom: 20px; line-height: inherit; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"><span style="box-sizing: inherit; font-weight: 700;">hprose_client.php</span></p><pre class="hljs xml" style="box-sizing: border-box; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 13px; word-break: break-word; overflow-wrap: normal; overflow: auto; position: relative; margin-top: 0px; margin-bottom: 20px; padding: 1em; border: none; border-radius: 4px; line-height: 1.5; background-color: rgb(246, 246, 246); color: rgb(51, 51, 51);"><?phpinclude("Hprose.php"); $client = new HproseHttpClient("http://127.0.0.1/hprose_server.php");echo "<br />"; $t = microtime(true);for ($i = 0; $i < 10000; $i++) $client->hello("world");echo microtime(true) - $t;echo "<br />"; $t = microtime(true);for ($i = 0; $i < 10000; $i++) $client->getUserList();echo microtime(true) - $t;</pre><h3 style="box-sizing: inherit; font-family: "PingFang SC", "Helvetica Neue", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", Sathu, EucrosiaUPC, Arial, Helvetica, sans-serif; line-height: 1.8; margin: 22px 0px 16px; padding: 0px; font-size: 22px; border: none; color: rgb(51, 51, 51); white-space: normal; background-color: rgb(255, 255, 255);">Yar HTTP 服务器和客户端</h3><p style="box-sizing: inherit; margin-top: 0px; margin-bottom: 20px; line-height: inherit; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"><span style="box-sizing: inherit; font-weight: 700;">yar_server.php</span></p><pre class="hljs xml" style="box-sizing: border-box; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 13px; word-break: break-word; overflow-wrap: normal; overflow: auto; position: relative; margin-top: 0px; margin-bottom: 20px; padding: 1em; border: none; border-radius: 4px; line-height: 1.5; background-color: rgb(246, 246, 246); color: rgb(51, 51, 51);"><?phpinclude("api.php"); $service = new Yar_Server(new API()); $service->handle();</pre><p style="box-sizing: inherit; margin-top: 0px; margin-bottom: 20px; line-height: inherit; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"><span style="box-sizing: inherit; font-weight: 700;">yar_client.php</span></p><pre class="hljs xml" style="box-sizing: border-box; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 13px; word-break: break-word; overflow-wrap: normal; overflow: auto; position: relative; margin-top: 0px; margin-bottom: 20px; padding: 1em; border: none; border-radius: 4px; line-height: 1.5; background-color: rgb(246, 246, 246); color: rgb(51, 51, 51);"><?php$client = new Yar_Client("http://127.0.0.1/yar_server.php");echo "<br />"; $t = microtime(true);for ($i = 0; $i < 10000; $i++) $client->hello("world");echo microtime(true) - $t;echo "<br />"; $t = microtime(true);for ($i = 0; $i < 10000; $i++) $client->getUserList();echo microtime(true) - $t;</pre><h3 style="box-sizing: inherit; font-family: "PingFang SC", "Helvetica Neue", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", Sathu, EucrosiaUPC, Arial, Helvetica, sans-serif; line-height: 1.8; margin: 22px 0px 16px; padding: 0px; font-size: 22px; border: none; color: rgb(51, 51, 51); white-space: normal; background-color: rgb(255, 255, 255);">Hprose Swoole HTTP 服务器和客户端</h3><p style="box-sizing: inherit; margin-top: 0px; margin-bottom: 20px; line-height: inherit; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"><span style="box-sizing: inherit; font-weight: 700;">hprose_swoole_http_server.php</span></p><pre class="hljs xml" style="box-sizing: border-box; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 13px; word-break: break-word; overflow-wrap: normal; overflow: auto; position: relative; margin-top: 0px; margin-bottom: 20px; padding: 1em; border: none; border-radius: 4px; line-height: 1.5; background-color: rgb(246, 246, 246); color: rgb(51, 51, 51);"><?phpinclude("Hprose.php");include("api.php"); $server = new HproseSwooleServer("http://127.0.0.1:8080/"); $server->addInstanceMethods(new API()); $server->start();</pre><p style="box-sizing: inherit; margin-top: 0px; margin-bottom: 20px; line-height: inherit; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"><span style="box-sizing: inherit; font-weight: 700;">hprose_swoole_http_client.php</span></p><pre class="hljs xml" style="box-sizing: border-box; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 13px; word-break: break-word; overflow-wrap: normal; overflow: auto; position: relative; margin-top: 0px; margin-bottom: 20px; padding: 1em; border: none; border-radius: 4px; line-height: 1.5; background-color: rgb(246, 246, 246); color: rgb(51, 51, 51);"><?phpinclude("Hprose.php"); $client = new HproseHttpClient("http://127.0.0.1:8080/");echo "<br />"; $t = microtime(true);for ($i = 0; $i < 10000; $i++) $client->hello("world");echo microtime(true) - $t;echo "<br />"; $t = microtime(true);for ($i = 0; $i < 10000; $i++) $client->getUserList();echo microtime(true) - $t;</pre><h3 style="box-sizing: inherit; font-family: "PingFang SC", "Helvetica Neue", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", Sathu, EucrosiaUPC, Arial, Helvetica, sans-serif; line-height: 1.8; margin: 22px 0px 16px; padding: 0px; font-size: 22px; border: none; color: rgb(51, 51, 51); white-space: normal; background-color: rgb(255, 255, 255);">Hprose Swoole TCP 服务器和客户端</h3><p style="box-sizing: inherit; margin-top: 0px; margin-bottom: 20px; line-height: inherit; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"><span style="box-sizing: inherit; font-weight: 700;">hprose_swoole_tcp_server.php</span></p><pre class="hljs xml" style="box-sizing: border-box; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 13px; word-break: break-word; overflow-wrap: normal; overflow: auto; position: relative; margin-top: 0px; margin-bottom: 20px; padding: 1em; border: none; border-radius: 4px; line-height: 1.5; background-color: rgb(246, 246, 246); color: rgb(51, 51, 51);"><?phpinclude("Hprose.php");include("api.php"); $server = new HproseSwooleServer("tcp://127.0.0.1:2015/"); $server->addInstanceMethods(new API()); $server->start();</pre><p style="box-sizing: inherit; margin-top: 0px; margin-bottom: 20px; line-height: inherit; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"><span style="box-sizing: inherit; font-weight: 700;">hprose_swoole_tcp_client.php</span></p><pre class="hljs xml" style="box-sizing: border-box; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 13px; word-break: break-word; overflow-wrap: normal; overflow: auto; position: relative; margin-top: 0px; margin-bottom: 20px; padding: 1em; border: none; border-radius: 4px; line-height: 1.5; background-color: rgb(246, 246, 246); color: rgb(51, 51, 51);"><?phpinclude("Hprose.php"); $client = new HproseSwooleClient("tcp://127.0.0.1:2015");echo "<br />"; $t = microtime(true);for ($i = 0; $i < 10000; $i++) $client->hello("world");echo microtime(true) - $t;echo "<br />"; $t = microtime(true);for ($i = 0; $i < 10000; $i++) $client->getUserList();echo microtime(true) - $t;</pre><h3 style="box-sizing: inherit; font-family: "PingFang SC", "Helvetica Neue", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", Sathu, EucrosiaUPC, Arial, Helvetica, sans-serif; line-height: 1.8; margin: 22px 0px 16px; padding: 0px; font-size: 22px; border: none; color: rgb(51, 51, 51); white-space: normal; background-color: rgb(255, 255, 255);">测试结果</h3><p style="box-sizing: inherit; margin-top: 0px; margin-bottom: 20px; line-height: inherit; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">下面是测试结果:</p><table width="776"><thead style="box-sizing: inherit; background: rgb(248, 248, 248);"><tr style="box-sizing: inherit; background-color: rgb(255, 255, 255);" class="firstRow"><th align="center" style="box-sizing: inherit; background: rgb(248, 248, 248); padding: 4px 8px; border-top-color: rgb(221, 221, 221);">服务器与客户端</th><th align="left" style="box-sizing: inherit; background: rgb(248, 248, 248); padding: 4px 8px; border-top-color: rgb(221, 221, 221);">hello</th><th align="left" style="box-sizing: inherit; background: rgb(248, 248, 248); padding: 4px 8px; border-top-color: rgb(221, 221, 221);">getUserList</th></tr></thead><tbody style="box-sizing: inherit;"><tr style="box-sizing: inherit;"><td align="center" style="box-sizing: inherit; padding: 4px 8px;">Hprose Swoole TCP</td><td align="left" style="box-sizing: inherit; padding: 4px 8px;">2.0799078941345秒</td><td align="left" style="box-sizing: inherit; padding: 4px 8px;">3.4906399250031 秒</td></tr><tr style="box-sizing: inherit; background-color: rgb(248, 248, 248);"><td align="center" style="box-sizing: inherit; padding: 4px 8px;">Hprose Swoole HTTP</td><td align="left" style="box-sizing: inherit; padding: 4px 8px;">2.9583330154419秒</td><td align="left" style="box-sizing: inherit; padding: 4px 8px;">4.2354850769043秒</td></tr><tr style="box-sizing: inherit;"><td align="center" style="box-sizing: inherit; padding: 4px 8px;">Yar HTTP</td><td align="left" style="box-sizing: inherit; padding: 4px 8px;">3.8473629951477秒</td><td align="left" style="box-sizing: inherit; padding: 4px 8px;">5.1223559379578秒</td></tr><tr style="box-sizing: inherit; background-color: rgb(248, 248, 248);"><td align="center" style="box-sizing: inherit; padding: 4px 8px;">Hprose HTTP</td><td align="left" style="box-sizing: inherit; padding: 4px 8px;">4.8670680522919秒</td><td align="left" style="box-sizing: inherit; padding: 4px 8px;">6.5057880878448秒</td></tr></tbody></table><p><br/></p>
CopyRight 2002~2023 精通2100网 联系邮箱:qqtxt@163.com
版权所有:精通2100网
湘ICP备2023018646号-1
MYSQl共执行 4 个查询,用时 0.0017077922821045 秒,PHP脚本用时 0.004431 秒,占用内存 0.655 MB,Gzip 已启用