{"id":48248,"date":"2024-12-02T13:52:06","date_gmt":"2024-12-02T05:52:06","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48248\/"},"modified":"2024-12-02T13:52:06","modified_gmt":"2024-12-02T05:52:06","slug":"php-%e5%87%bd%e6%95%b0%e6%80%a7%e8%83%bd%e4%bc%98%e5%8c%96%e4%b8%ad%e7%9a%84%e5%9f%ba%e5%87%86%e6%b5%8b%e8%af%95%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48248\/","title":{"rendered":"PHP \u51fd\u6570\u6027\u80fd\u4f18\u5316\u4e2d\u7684\u57fa\u51c6\u6d4b\u8bd5\u5b9e\u8df5"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u6027\u80fd\u4f18\u5316\u4e2d\u7684\u57fa\u51c6\u6d4b\u8bd5\u5b9e\u8df5<\/h1>\n<p>\u5728\u6587\u7ae0\u5b9e\u6218\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u4e00\u4e9b\u8fd9\u6837\u90a3\u6837\u7684\u95ee\u9898\uff0c\u7136\u540e\u8981\u5361\u597d\u534a\u5929\uff0c\u7b49\u95ee\u9898\u89e3\u51b3\u4e86\u624d\u53d1\u73b0\u539f\u6765\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u662f\u6ca1\u6709\u638c\u63e1\u597d\u3002\u4eca\u5929\u7c73\u4e91\u5c31\u6574\u7406\u5206\u4eab\u300aPHP \u51fd\u6570\u6027\u80fd\u4f18\u5316\u4e2d\u7684\u57fa\u51c6\u6d4b\u8bd5\u5b9e\u8df5\u300b\uff0c\u804a\u804a\uff0c\u5e0c\u671b\u53ef\u4ee5\u5e2e\u52a9\u5230\u6b63\u5728\u52aa\u529b\u8d5a\u94b1\u7684\u4f60\u3002<\/p>\n<p>\u57fa\u51c6\u6d4b\u8bd5\u5bf9\u4e8e\u8bc4\u4f30\u548c\u4f18\u5316 PHP \u51fd\u6570\u6027\u80fd\u81f3\u5173\u91cd\u8981\uff0c\u6d89\u53ca\u6d4b\u91cf\u6267\u884c\u65f6\u95f4\u5e76\u8fdb\u884c\u6539\u8fdb\u3002\u6700\u4f73\u5b9e\u8df5\u5305\u62ec\u4f7f\u7528\u57fa\u51c6\u6d4b\u8bd5\u5e93\u3001\u8fd0\u884c\u591a\u6b21\u6d4b\u8bd5\u3001\u4f7f\u7528\u9002\u5f53\u6570\u636e\u96c6\u3001\u63a7\u5236\u73af\u5883\u548c\u6bd4\u8f83\u4e0d\u540c\u5b9e\u73b0\u3002\u5b9e\u6218\u6848\u4f8b\u4e2d\uff0cstrcmp_bin \u6bd4strcmp\u548cstrcasecmp\u5feb\u51e0\u4e2a\u6570\u91cf\u7ea7\uff0c\u56e0\u4e3a\u5b83\u8fdb\u884c\u4e8c\u8fdb\u5236\u6bd4\u8f83\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1730004872671dc788adbb5.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u6027\u80fd\u4f18\u5316\u4e2d\u7684\u57fa\u51c6\u6d4b\u8bd5\u5b9e\u8df5\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u6027\u80fd\u4f18\u5316\u4e2d\u7684\u57fa\u51c6\u6d4b\u8bd5\u5b9e\u8df5\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u6027\u80fd\u4f18\u5316\u4e2d\u7684\u57fa\u51c6\u6d4b\u8bd5\u5b9e\u8df5<\/strong><\/p>\n<p>\u57fa\u51c6\u6d4b\u8bd5\u662f\u8bc4\u4f30\u548c\u4f18\u5316 PHP \u51fd\u6570\u6027\u80fd\u7684\u5173\u952e\u6b65\u9aa4\u3002\u5b83\u6d89\u53ca\u6d4b\u91cf\u4ee3\u7801\u6267\u884c\u6240\u9700\u7684\u65f6\u95f4\uff0c\u5e76\u6839\u636e\u7ed3\u679c\u8fdb\u884c\u6539\u8fdb\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5728 PHP \u51fd\u6570\u6027\u80fd\u4f18\u5316\u4e2d\u8fdb\u884c\u57fa\u51c6\u6d4b\u8bd5\u7684\u6700\u4f73\u5b9e\u8df5\uff0c\u5e76\u63d0\u4f9b\u4e86\u5b9e\u6218\u6848\u4f8b\u3002<\/p>\n<p><strong>\u6700\u4f73\u5b9e\u8df5\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u6807\u51c6\u57fa\u51c6\u6d4b\u8bd5\u5e93\uff1a<\/strong>\u4f8b\u5982 [PHPBench](https:\/\/github.com\/Roave\/phpbench)\uff0c\u5b83\u63d0\u4f9b\u4e86\u6210\u719f\u7684\u65b9\u6cd5\u548c\u62a5\u544a\u751f\u6210\u5de5\u5177\u3002<\/li>\n<li><strong>\u8fd0\u884c\u591a\u6b21\u6d4b\u8bd5\uff1a<\/strong>\u6d88\u9664\u5f02\u5e38\u503c\u5e76\u83b7\u5f97\u51c6\u786e\u7684\u7ed3\u679c\u3002<\/li>\n<li><strong>\u4f7f\u7528\u9002\u5f53\u7684\u6570\u636e\u96c6\uff1a<\/strong>\u9009\u62e9\u4ee3\u8868\u5b9e\u9645\u573a\u666f\u7684\u8f93\u5165\u6570\u636e\u3002<\/li>\n<li><strong>\u63a7\u5236\u73af\u5883\uff1a<\/strong>\u786e\u4fdd\u6bcf\u6b21\u8fd0\u884c\u65f6\u7cfb\u7edf\u8d44\u6e90\u90fd\u76f8\u540c\u3002<\/li>\n<li><strong>\u6bd4\u8f83\u4e0d\u540c\u7684\u5b9e\u73b0\uff1a<\/strong>\u6d4b\u8bd5\u4e0d\u540c\u5b9e\u73b0\uff08\u4f8b\u5982\uff0c\u539f\u751f PHP \u51fd\u6570\u3001\u7b2c\u4e09\u65b9\u5e93\uff09\u4e4b\u95f4\u7684\u6027\u80fd\u5dee\u5f02\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a\u5b57\u7b26\u4e32\u6bd4\u8f83\u51fd\u6570<\/strong><\/p>\n<p>\u8003\u8651\u4ee5\u4e0b\u4e09\u4e2a PHP \u5b57\u7b26\u4e32\u6bd4\u8f83\u51fd\u6570\uff1a<\/p>\n<pre>function strcmp($str1, $str2) {}\nfunction strcasecmp($str1, $str2) {}\nfunction strcmp_bin($str1, $str2) {}<\/pre>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 PHPBench \u5bf9\u5176\u6027\u80fd\u8fdb\u884c\u57fa\u51c6\u6d4b\u8bd5\uff1a<\/p>\n<pre>use PhpBench\\Benchmark\\Metadata\\Annotations\\Groups;\nuse PhpBench\\Benchmark\\Metadata\\Annotations\\Iterations;\nuse PhpBench\\Benchmark\\Metadata\\Annotations\\Revs;\n\nclass StringComparisonBench\n{\n    \/**\n     * @Groups({\"comparison\"})\n     * @Iterations(1000)\n     * @Revs(100)\n     *\/\n    public function benchStrcmp(): void\n    {\n        strcmp('test', 'test');\n    }\n\n    \/**\n     * @Groups({\"comparison\"})\n     * @Iterations(1000)\n     * @Revs(100)\n     *\/\n    public function benchStrcasecmp(): void\n    {\n        strcasecmp('test', 'test');\n    }\n\n    \/**\n     * @Groups({\"comparison\"})\n     * @Iterations(1000)\n     * @Revs(100)\n     *\/\n    public function benchStrcmpBin(): void\n    {\n        strcmp_bin('test', 'test');\n    }\n}<\/pre>\n<p>\u7ed3\u679c\u8868\u660e\uff0c<code>strcmp_bin<\/code> \u6bd4\u5176\u4ed6\u4e24\u4e2a\u51fd\u6570\u5feb\u51e0\u4e2a\u6570\u91cf\u7ea7\uff0c\u56e0\u4e3a\u5b83\u8fdb\u884c\u4e8c\u8fdb\u5236\u6bd4\u8f83\uff0c\u800c <code>strcmp<\/code> \u548c <code>strcasecmp<\/code> \u8fdb\u884c\u5b57\u7b26\u6bd4\u8f83\u3002<\/p>\n<p>\u6587\u4e2d\u5173\u4e8ephp,\u6027\u80fd\u4f18\u5316\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aPHP \u51fd\u6570\u6027\u80fd\u4f18\u5316\u4e2d\u7684\u57fa\u51c6\u6d4b\u8bd5\u5b9e\u8df5\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u6027\u80fd\u4f18\u5316\u4e2d\u7684\u57fa\u51c6\u6d4b\u8bd5\u5b9e\u8df5 \u5728\u6587\u7ae0\u5b9e\u6218\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u4e00\u4e9b\u8fd9\u6837\u90a3\u6837\u7684\u95ee\u9898\uff0c\u7136\u540e\u8981\u5361\u597d\u534a\u5929\uff0c\u7b49\u95ee\u9898\u89e3\u51b3\u4e86\u624d\u53d1\u73b0\u539f\u6765\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u662f\u6ca1\u6709\u638c\u63e1\u597d\u3002\u4eca\u5929\u7c73\u4e91\u5c31\u6574\u7406\u5206\u4eab\u300aPHP \u51fd\u6570\u6027\u80fd\u4f18\u5316\u4e2d\u7684\u57fa\u51c6\u6d4b\u8bd5\u5b9e\u8df5\u300b\uff0c\u804a\u804a\uff0c\u5e0c\u671b\u53ef\u4ee5\u5e2e\u52a9\u5230\u6b63\u5728\u52aa\u529b\u8d5a\u94b1\u7684\u4f60\u3002 \u57fa\u51c6\u6d4b\u8bd5\u5bf9\u4e8e\u8bc4\u4f30\u548c\u4f18\u5316 PHP \u51fd\u6570\u6027\u80fd\u81f3\u5173\u91cd\u8981\uff0c\u6d89\u53ca\u6d4b\u91cf\u6267\u884c\u65f6\u95f4\u5e76\u8fdb\u884c\u6539\u8fdb\u3002\u6700\u4f73\u5b9e\u8df5\u5305\u62ec\u4f7f\u7528\u57fa\u51c6\u6d4b\u8bd5\u5e93\u3001\u8fd0\u884c\u591a\u6b21\u6d4b\u8bd5\u3001\u4f7f\u7528\u9002\u5f53\u6570\u636e\u96c6\u3001\u63a7\u5236\u73af\u5883\u548c\u6bd4\u8f83\u4e0d\u540c\u5b9e\u73b0\u3002\u5b9e\u6218\u6848\u4f8b\u4e2d\uff0cstrcmp_bin \u6bd4strcmp\u548cstrcasecmp\u5feb\u51e0\u4e2a\u6570\u91cf\u7ea7\uff0c\u56e0\u4e3a\u5b83\u8fdb\u884c\u4e8c\u8fdb\u5236\u6bd4\u8f83\u3002 PHP \u51fd\u6570\u6027\u80fd\u4f18\u5316\u4e2d\u7684\u57fa\u51c6\u6d4b\u8bd5\u5b9e\u8df5 \u57fa\u51c6\u6d4b\u8bd5\u662f\u8bc4\u4f30\u548c\u4f18\u5316 PHP \u51fd\u6570\u6027\u80fd\u7684\u5173\u952e\u6b65\u9aa4\u3002\u5b83\u6d89\u53ca\u6d4b\u91cf\u4ee3\u7801\u6267\u884c\u6240\u9700\u7684\u65f6\u95f4\uff0c\u5e76\u6839\u636e\u7ed3\u679c\u8fdb\u884c\u6539\u8fdb\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5728 PHP \u51fd\u6570\u6027\u80fd\u4f18\u5316\u4e2d\u8fdb\u884c\u57fa\u51c6\u6d4b\u8bd5\u7684\u6700\u4f73\u5b9e\u8df5\uff0c\u5e76\u63d0\u4f9b\u4e86\u5b9e\u6218\u6848\u4f8b\u3002 \u6700\u4f73\u5b9e\u8df5\uff1a \u4f7f\u7528\u6807\u51c6\u57fa\u51c6\u6d4b\u8bd5\u5e93\uff1a\u4f8b\u5982 [PHPBench](https:\/\/github.com\/Roave\/phpbench)\uff0c\u5b83\u63d0\u4f9b\u4e86\u6210\u719f\u7684\u65b9\u6cd5\u548c\u62a5\u544a\u751f\u6210\u5de5\u5177\u3002 \u8fd0\u884c\u591a\u6b21\u6d4b\u8bd5\uff1a\u6d88\u9664\u5f02\u5e38\u503c\u5e76\u83b7\u5f97\u51c6\u786e\u7684\u7ed3\u679c\u3002 \u4f7f\u7528\u9002\u5f53\u7684\u6570\u636e\u96c6\uff1a\u9009\u62e9\u4ee3\u8868\u5b9e\u9645\u573a\u666f\u7684\u8f93\u5165\u6570\u636e\u3002 \u63a7\u5236\u73af\u5883\uff1a\u786e\u4fdd\u6bcf\u6b21\u8fd0\u884c\u65f6\u7cfb\u7edf\u8d44\u6e90\u90fd\u76f8\u540c\u3002 \u6bd4\u8f83\u4e0d\u540c\u7684\u5b9e\u73b0\uff1a\u6d4b\u8bd5\u4e0d\u540c\u5b9e\u73b0\uff08\u4f8b\u5982\uff0c\u539f\u751f PHP \u51fd\u6570\u3001\u7b2c\u4e09\u65b9\u5e93\uff09\u4e4b\u95f4\u7684\u6027\u80fd\u5dee\u5f02\u3002 \u5b9e\u6218\u6848\u4f8b\uff1a\u5b57\u7b26\u4e32\u6bd4\u8f83\u51fd\u6570 \u8003\u8651\u4ee5\u4e0b\u4e09\u4e2a PHP \u5b57\u7b26\u4e32\u6bd4\u8f83\u51fd\u6570\uff1a function strcmp($str1, $str2) {} function strcasecmp($str1, $str2) {} function strcmp_bin($str1, $str2) {} \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 PHPBench \u5bf9\u5176\u6027\u80fd\u8fdb\u884c\u57fa\u51c6\u6d4b\u8bd5\uff1a use PhpBench\\Benchmark\\Metadata\\Annotations\\Groups; use PhpBench\\Benchmark\\Metadata\\Annotations\\Iterations; use PhpBench\\Benchmark\\Metadata\\Annotations\\Revs; class StringComparisonBench { \/** * @Groups({&#8220;comparison&#8221;}) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-48248","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=48248"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48248\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}