{"id":1534,"date":"2017-04-14T22:02:14","date_gmt":"2017-04-14T14:02:14","guid":{"rendered":"http:\/\/ufqi.com\/blog\/?p=1534"},"modified":"2017-04-17T14:23:20","modified_gmt":"2017-04-17T06:23:20","slug":"201-php-performance-built-in-vs-script","status":"publish","type":"post","link":"https:\/\/ufqi.com\/blog\/201-php-performance-built-in-vs-script\/","title":{"rendered":"20:1, PHP\u6027\u80fd\u8bc4\u6d4bBase62x:\u5185\u7f6e\u6a21\u5757 vs. \u811a\u672c\u6a21\u5757"},"content":{"rendered":"<p>\u4e0a\u7bc7(\u00a0<a class=\"bigfont\" href=\"https:\/\/ufqi.com\/url4p\/?sid=798818&amp;act=query&amp;shortkey=P2SN\" target=\"_blank\">-R\/P2SN<\/a> )\u6211\u4eec\u6982\u62ec\u5730\u89e3\u91ca\u4e86\u4f7f\u7528\u670d\u52a1\u5668\u7aef\u3001\u5ba2\u6237\u7aef\u5404\u79cd\u7f13\u5b58\u3001\u538b\u7f29\u4f18\u5316\u63d0\u901f-gMIS\u7b49\u624b\u6bb5. \u8fd9\u6b21\u66f4\u5177\u4f53\u5230\u7f16\u7a0b\u8bed\u8a00\u5c42\u9762\u8ba8\u8bba\u4f18\u5316\u3002\u884c\u6587\u6b64\u524d\u80cc\u666f\uff1a<br \/>1. \u00a0-gwa2 vs -thinkphp,\u00a0<b><a class=\"bigfont\" href=\"https:\/\/ufqi.com\/url4p\/?sid=539019&amp;act=query&amp;shortkey=92SJ\" target=\"_blank\">-R\/92SJ<\/a> <br \/>2.\u00a0php\u7684\u6240\u8c13\u4f18\u5316,\u00a0<a class=\"bigfont\" href=\"https:\/\/ufqi.com\/url4p\/?sid=539019&amp;act=query&amp;shortkey=22SK\" target=\"_blank\">-R\/22SK<\/a> <br \/>3.\u00a0\u5173\u4e8eLog4j\u548cSysytem.out.println\u7684\u6027\u80fd\u6bd4\u8f83\u6d4b\u8bd5,\u00a0<a class=\"bigfont\" href=\"https:\/\/ufqi.com\/url4p\/?sid=539019&amp;act=query&amp;shortkey=I2SL\" target=\"_blank\">-R\/I2SL<\/a> <\/b><\/p>\n<p>\u5173\u4e8eJava\uff0fPHP\u7684\u6027\u80fd\u8bc4\u6d4b\u548c\u4f18\u5316\uff0c\u5927\u81f4\u7ed3\u8bba\u662f\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff08OOP\uff09\u7b49\u662f\u62ff\u6027\u80fd\u6362\u4fbf\u5229\uff08Convenience\uff09\u3001\u5f3a\u58ee\uff08Robustness\uff09\u7b49\uff0c\u9664\u4e86\u63cf\u7ed8\u5ba2\u89c2\u590d\u6742\u4e16\u754c\u6240\u9700\u5916\uff0c\u6df1\u5c42\u7684\u53e6\u56e0\u53ef\u80fd\u662f\u786c\u4ef6\u6027\u80fd\u8d8a\u6765\u4fbf\u5b9c\uff0c\u800c\u4eba\u5de5\u8d8a\u6765\u6602\u8d35\u3002\u672c\u6587\u53ef\u4ee5\u770b\u4f5c\u662f\u5176\u4e2d 2. \u7684\u63a5\u7eed\uff0c\u5c1d\u8bd5\u63a2\u7d22\u7684\u662f\uff0c\u5728PHP\u7f16\u7a0b\u4e2d\uff0c\u4f7f\u7528C\u8bed\u8a00\u7b49\u5b9e\u73b0\u7684Module\/\u6a21\u5757\uff08\u5185\u7f6e\u6a21\u5757\uff09\u6bd4PHP\u811a\u672c\u5199\u7684Module\/\u6a21\u5757\uff08\u811a\u672c\u6a21\u5757\uff09\u5feb\u5417? \u5982\u679c\u5feb\uff0c\u540c\u6837\u7684\u529f\u80fd\uff0c\u80fd\u5feb\u591a\u5c11\uff1f<\/p>\n<p>\u8ddd\u79bb\u4e0a\u6b21\u8fdb\u884c\u7c7b\u4f3c\u7684\u6d4b\u8bd5\uff0c\u5df2\u7ecf\u5341\u591a\u5e74\u8fc7\u53bb\u4e86\uff0cPHP\u548cJava\u90fd\u53d1\u5c55\u4e86\u5f88\u591a\u7248\u672c\uff0c\u65e5\u76ca\u6210\u719f\u548c\u7a33\u5b9a\uff0c\u800cC\u8bed\u8a00\u5374\u4fdd\u6301\u4e86\u76f8\u5bf9\u7684\u7a33\u5b9a\uff0c\u73b0\u5728\u91cd\u65b0\u505a\u4e00\u4e9b\u8fd9\u6837\u7684\u6027\u80fd\u5bf9\u6bd4\uff0c\u9887\u6709\u65f6\u7a7a\u611f\u3002<\/p>\n<p>\u8981\u505a\u8fd9\u6837\u7684\u5b9e\u9a8c\u800c\u4e14\u6709\u4e00\u5b9a\u5b9e\u9645\u610f\u4e49\u7684\u8bdd\uff0c\u673a\u4f1a\u8981\u7b49\u6216\u8005\u78b0\u7684\uff0c\u6b64\u524d\u8fdb\u884c\u7684\u5c06 -Base62x \u8fdb\u884c\u591a\u7248\u672c\u8bed\u8a00\u5f00\u53d1\u5de5\u4f5c\uff0c\u521a\u597d\u80fd\u6ee1\u8db3\u8fd9\u4e00\u5b9e\u9a8c\u7684\u76ee\u7684\u3002\u6211\u4eec\u6210\u529f\u5c06\u5730C\u8bed\u8a00\u7684 -Base62x \u7f16\u8bd1\u6210PHP 7 \u7684\u4e00\u4e2aext\u6a21\u5757 ext\/base62x \uff0c\u540c\u65f6\u4e5f\u4f7f\u7528PHP\u811a\u672c\u8bed\u8a00\u5b9e\u73b0\u4e86 -Base62x \u7684\u7248\u672c\uff0c\u540d\u4e3a base62x.class.php, \u76f8\u5e94\u5730\u4ee3\u7801\u90fd\u53ef\u4ee5\u4ece -github-wadelau \u4e0b\u8f7d\u83b7\u5f97\u3002<\/p>\n<p>\u6709\u4e86\u8fd9\u4e9b\u51c6\u5907\u5de5\u4f5c\uff0c\u6211\u4eec\u8981\u8fdb\u884c\u7684\u5b9e\u9a8c\u662f\u4f7f\u7528\u540c\u6837\u7684\u7b97\u6cd5\uff0c\u5bf9\u4e00\u6bb5\u6587\u672c\u8fdb\u884c -Base62x \u7f16\u7801\uff0cC\u8bed\u8a00\u5b9e\u73b0\u7684PHP ext\/base62x \u6a21\u5757\u4f1a\u6bd4\u4f7f\u7528PHP\u811a\u672c\u7f16\u5199\u7684 base62x.class.php \u8fd0\u884c\u5f97\u5feb\u5417? \u80fd\u5feb\u591a\u5c11?<\/p>\n<p>\u57fa\u4e8e\u6b64\uff0c\u6211\u4eec\u7f16\u5199\u4e86\u6d4b\u8bd5\u7a0b\u5e8f\uff0c\u8fdb\u884c\u4e00\u4e07\u6b21\u968f\u673a\u5b57\u7b26\u4e32\u7684 base62x \u7f16\u7801\uff0c\u5c06\u5176\u8fd0\u884c\u8017\u8d39\u65f6\u95f4\u8fdb\u884c\u8bb0\u5f55\u5bf9\u6bd4\u3002<\/p>\n<p>\u6d4b\u8bd5\u7a0b\u5e8f\u4e3b\u4f53\uff0c basetest.php<br \/>\u4f7f\u7528base62x.class.php\u7684\u7f16\u7801\u65b9\u6cd5\uff0c\u00a0<br \/>\u00a0 \u00a0 \u00a0 $b62x = new Base62x();<br \/>\u00a0 \u00a0 \u00a0 $s_encoded = $b62x-&gt;encode($s);<br \/>\u4f7f\u7528PHP\u5185\u7f6eC\u8bed\u8a00\u5b9e\u73b0\u7684\u540c\u6837\u7b97\u6cd5\u6a21\u5757base62x.c\u7684\u7f16\u7801\u65b9\u6cd5\uff0c<br \/>\u00a0 \u00a0 \u00a0 $s_encoded = base62x_encode($s);<\/p>\n<p>\u4f7f\u7528C\u8bed\u8a00\u7684\u6a21\u5757\u9700\u8981\u91cd\u65b0\u7f16\u8bd1PHP\u7684\u5b89\u88c5\u76ee\u5f55\u5bf9\u5e94\u7684\u7a0b\u5e8f\uff0c\u5173\u4e8e\u7f16\u5236PHP\u6269\u5c55\u6a21\u5757\u7684\u8be6\u7ec6\u64cd\u4f5c\u53c2\u8003\uff0c<a href=\"http:\/\/ufqi.com\/naturedns\/search?q=-r\/d2SH\">-R\/d2SH<\/a> , <a href=\"http:\/\/ufqi.com\/naturedns\/search?q=-r\/M2SJ\">-R\/M2SJ<\/a> .<\/p>\n<p>\u5206\u522b\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\u8fdb\u884c10,000\u6b21\u7f16\u7801\uff0c\u4f7f\u7528PHP\u7684\u5185\u7f6e\u51fd\u6570microtime\u8fdb\u884c\u8ba1\u65f6\uff0c\u8bb0\u5f55\u6bcf\u8fdb\u884c10,000\u6b21\u7f16\u7801\u64cd\u4f5c\u65f6\uff0c\u4e24\u8005\u6240\u82b1\u8d39\u7684\u65f6\u95f4\uff0c\u91cd\u590d\u8fdb\u884c10\u6b21\uff0c\u8bb0\u5f55\u5217\u5982\u4e0b\u3002<\/p>\n<p>base62x.class vs. base62x.c for 10K strings encoded operations<\/p>\n<table width=\"408\">\n<tbody>\n<tr>\n<td width=\"64\">\u00a0<\/td>\n<td width=\"138\"><span style=\"color: #000000\"><b>Time cost for<\/b><\/span><\/td>\n<td width=\"122\"><span style=\"color: #000000\"><b>Time cost for<\/b><\/span><\/td>\n<td width=\"84\"><strong>\u00a0<\/strong><\/td>\n<\/tr>\n<tr>\n<td><strong>\u00a0<\/strong><\/td>\n<td><strong>base62x.class.php<\/strong><\/td>\n<td><strong>base62x.c<\/strong><\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>0.15378499<\/td>\n<td>0.006615877<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>0.154273987<\/td>\n<td>0.006779909<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>0.161313057<\/td>\n<td>0.00666213<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>0.178726912<\/td>\n<td>0.00667119<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>0.193426132<\/td>\n<td>0.007475138<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>0.162053108<\/td>\n<td>0.00752902<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>0.169737101<\/td>\n<td>0.00692296<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>0.155719995<\/td>\n<td>0.006750107<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>9<\/td>\n<td>0.164766073<\/td>\n<td>0.007402897<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>10<\/td>\n<td>0.196639061<\/td>\n<td>0.006860018<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0<\/td>\n<td>\u00a0<\/td>\n<td>\u00a0<\/td>\n<td>Faster x<\/td>\n<\/tr>\n<tr>\n<td>avg<\/td>\n<td>0.169044042<\/td>\n<td>0.006966925<\/td>\n<td>24.2637964<\/td>\n<\/tr>\n<tr>\n<td>max<\/td>\n<td>0.196639061<\/td>\n<td>0.00752902<\/td>\n<td>26.11748314<\/td>\n<\/tr>\n<tr>\n<td>min<\/td>\n<td>0.15378499<\/td>\n<td>0.006615877<\/td>\n<td>23.24483765<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6d4b\u8bd5\u4e3b\u673a\u73af\u5883\u4e3a\u666e\u901a\u53f0\u5f0f\u673aPC\u4e0a\u8fd0\u884c\u7684VMWare Station\u4e2d\u8fd0\u884c\u7684OpenSuSE Linux Leap 64bit\uff0cPHP 7.0.<\/p>\n<p>\u8fd0\u884c\u6570\u636e\u663e\u793a\uff0c\u4f7f\u7528PHP\u811a\u672c\u8bed\u8a00\u5b9e\u73b0\u7684base62x.class\u8fdb\u884c\u4e00\u4e07\u6b21\u7f16\u7801\u5e73\u5747\u9700\u8981\u82b1\u8d390.1690\u79d2\uff0c\u4e5f\u5373\u9700\u8981169.0ms\uff1b\u800c\u4f7f\u7528C\u8bed\u8a00\u5b9e\u73b0\u7684\u540c\u6837\u7684\u7b97\u6cd5\u7684base62x\u7b97\u6cd5\u7684\u4e00\u4e07\u6b21\u7f16\u7801\u5e73\u5747\u9700\u8981\u82b1\u8d39\u7684\u65f6\u95f4\u4e3a0.0070\u79d2\uff0c\u4e5f\u53737.0ms\uff1b\u4e24\u76f8\u6bd4\u8f83\uff0c\u524d\u8005\u662f\u540e\u8005\u768424\u500d\uff0c\u4e5f\u5373base62x.class\u6bd4base62x.c\u591a\u7528\u4e8620\u591a\u500d\u7684\u65f6\u95f4\uff0c\u540e\u8005\u6bd4\u524d\u8005\u5feb\u4e8620\u591a\u500d\u3002<\/p>\n<p>\u8fdb\u4e00\u6b65\u5730\u62c9\u957f\u4e0e\u4e4b\u524d\u7684\u5bf9\u6bd4\uff0cPHP\u7684\u4f18\u5316\u601d\u8def\uff0c\u4f18\u5316\u903b\u8f91\uff0c\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u64cd\u4f5c\u6b65\u9aa4\uff0c\u51cf\u5c11\u81ea\u5b9a\u4e49\u7684\u65b9\u6cd5\u3001\u7c7b\u5e93\uff0c\u5c3d\u91cf\u4f7f\u7528\u5185\u7f6e\u65b9\u6cd5\u3001\u7c7b\u5e93\uff0c\u5f53\u8fd9\u4e9b\u8fd8\u4e0d\u8db3\u591f\u5feb\u65f6\uff0c\u7ec8\u6781\u63d0\u901f\u6216\u8005\u80fd\u6709\u8f83\u5927\u63d0\u901f\u7684\u5c31\u662f\u4f7f\u7528\u7c7b\u4f3cC\u8bed\u8a00\u4ee5PHP\u6269\u5c55\u6a21\u5757\u7684\u65b9\u5f0f\u8fdb\u884c\u5c1d\u8bd5\u3002<\/p>\n<p>\u9488\u5bf9\u8fd9\u4e2a\u7ec8\u6781\u4f18\u5316\u601d\u8def\uff0c\u4e4b\u524d\u53ea\u662f\u5b9a\u6027\u7684\u5206\u6790\uff0c\u8fd9\u6b21\u6709\u4e86\u5b9a\u91cf\u7684\u5206\u6790\uff0c\u5370\u8bc1\u4e86\u4e4b\u524d\u7684\u5206\u6790\u548c\u63a8\u6d4b\u3002<\/p>\n<p>\u7ed3\u5408\u4e4b\u524d\u63d0\u5230\u7684\u9488\u5bf9 Java \u7684 Log4j \u548c System.out.println \u5bf9\u6bd4\uff0c\u4f3c\u4e4e\u8fd9\u79cd\u7ec8\u6781\u4f18\u5316\u4e5f\u53ef\u4ee5\u5e94\u7528\u5230 Java \u7684\u7f16\u7a0b\u4e2d\uff0c\u901a\u8fc7\u4f7f\u7528JNI\u8c03\u7528Java\u5bf9\u5916\u90e8C\uff0fC++\u7b49\u5b9e\u73b0\u7684\u6269\u5c55\uff0c\u4e5f\u80fd\u5426\u53d6\u5f9720:1\u70b9\u63d0\u901f\u6548\u679c\uff0c\u8fd9\u8fd8\u6709\u5f85\u8fdb\u4e00\u6b65\u5730\u5b9e\u9a8c\u3002<\/p>\n<p>\u7ecf\u6b21\u5b9e\u9a8c\u53ef\u4ee5\u5927\u81f4\u5730\u5f97\u51fa\uff0c\u540c\u6837\u7b97\u6cd5\uff0c\u4f7f\u7528C\u8bed\u8a00\u5b9e\u73b0\u7684PHP\u6269\u5c55\u7684\u5185\u7f6e\u6a21\u5757\u6bd4\u4f7f\u7528PHP\u811a\u672c\u7f16\u5199\u7684OOP\u6a21\u5757\u8981\u5feb\u5f88\u591a\uff0c\u5176\u6bd4\u503c\u5927\u7ea6\u5728 20:1 \u5de6\u53f3\u3002<\/p>\n<p><img src=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/09\/b62x-icon-201306.png\" \/><\/p>\n<h4>Base62x: An Alternative Approach to Base64 for non-Alphanumeric Characters.<br \/>Base62x \u662f\u65e0\u7b26\u53f7\u7684Base64\u7f16\u7801\u65b9\u6848\u3002\u5728\u6587\u4ef6\u7cfb\u7edf\u3001\u7f51\u7edc\u7cfb\u7edf\u4e2d\u53ef\u4ee5\u5b89\u5168\u5730\u4f7f\u7528\uff0c\u540c\u65f6\u662f\u5404\u79cd\u53d8\u79cdBase64\u7f16\u7801\u65b9\u6848\u7684\u7406\u60f3\u66ff\u4ee3\u54c1\u3002<\/h4>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u7bc7(\u00a0-R\/P2SN )\u6211\u4eec\u6982\u62ec\u5730\u89e3\u91ca\u4e86\u4f7f\u7528\u670d\u52a1\u5668\u7aef\u3001\u5ba2\u6237\u7aef\u5404\u79cd\u7f13\u5b58\u3001\u538b\u7f29\u4f18\u5316 &hellip; <a href=\"https:\/\/ufqi.com\/blog\/201-php-performance-built-in-vs-script\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":1487,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[161,6,2],"tags":[154,84,138,184],"_links":{"self":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1534"}],"collection":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/comments?post=1534"}],"version-history":[{"count":15,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1534\/revisions"}],"predecessor-version":[{"id":1549,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1534\/revisions\/1549"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/media\/1487"}],"wp:attachment":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/media?parent=1534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/categories?post=1534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/tags?post=1534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}