ΪʲôҪʹÓà SPLÖÐµÄ SplQueueʵÏÖ¶ÓÁÐ
2019-05-16 23:58:40À´Ô´£º²©¿ÍÔ° ÔĶÁ ()
½ñÌì¿´phpµÄSPL±ê×¼¿â²¿·ÖÀïÃæÉæ¼°µ½Êý¾Ý½á¹¹ÆäÖÐÓÐ SplQueue À´ÊµÏÖ¶ÓÁÐЧ¹û£¬µ«ÊÇÎÒ¸Õ½Ó´¥phpµÄʱºòѧϰµ½µÄÊÇ Ê¹ÓÃarrayµÄ array_push ºÍ array_pop ¾Í¿ÉÒÔʵÏÖ¶ÓÁÐЧ¹ûÀ²°¡£¬ÄÇô˵ SPLÖеÄÕâ¸öÊDz»ÊÇÏԵúܼ¦ÀßÄØ£¿£¿ºóÀ´½ø¹ý²éѯ×ÊÁϲ¢ÇÒʵ¼ÊÔËÐÐһϳÌÐòºó·¢ÏÖ£¬ÆäʵÔÚÐÔÄÜ·½Ã棬ʹÓÃsplµÄÊý¾Ý½á¹¹±ÈʹÓÃarrayÄ£Äâ³öÀ´µÄ¶ÓÁÐÔÚÐÔÄÜÉÏÇ¿ºÜ¶à£º
arrayÊý×éÄ£Äâ¶ÓÁУ¬´¦Àí100000ÈÎÎñ
list($t1, $t2) = explode(' ', microtime()); $st = (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000); $arrq = array(); for($i = 0; $i <100000; $i++) { $data = "hello $i\n"; array_push($arrq, $data); if ($i % 100 == 99 and count($arrq) > 100) { $popN = rand(10, 99); for ($j = 0; $j < $popN; $j++) { array_shift($arrq); } } } $popN = count($arrq); for ($j = 0; $j < $popN; $j++) { array_shift($arrq); } list($t1, $t2) = explode(' ', microtime()); $et = (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000); echo $et - $st;
Ö´ÐÐÈý´Îȡƽ¾ùֵΪ£º3900 ms
ʹÓÃSplQueue
list($t1, $t2) = explode(' ', microtime()); $st = (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000); $splq = new SplQueue; for($i = 0; $i < 100000; $i++) { $data = "hello $i\n"; $splq->push($data); if ($i % 100 == 99 and count($splq) > 100) { $popN = rand(10, 99); for ($j = 0; $j < $popN; $j++) { $splq->shift(); } } } list($t1, $t2) = explode(' ', microtime()); $et = (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000); echo $et - $st;
Ö´ÐÐÈý´Îȡƽ¾ùֵΪ£º117 ms
ÐÔÄÜÌáÉý 33 ±¶
¹ØÓÚspl±ê×¼¿âÕâ¿é£¬¿´À´»¹Òª¶àÑо¿Ñо¿£¬¼ÈÈ»ÎĵµÖÐÓÐÕâ¸ö¿â£¬ÄÇô¿Ï¶¨ÓÐËü¶ÀÌصĵط½£¡
²Î¿¼Îĵµ £ºhttps://wiki.swoole.com/wiki/page/507.html
ÔÎÄÁ´½Ó:https://www.cnblogs.com/itsuibi/p/10870608.html
ÈçÓÐÒÉÎÊÇëÓëÔ×÷ÕßÁªÏµ
±êÇ©£º
°æȨÉêÃ÷£º±¾Õ¾ÎÄÕ²¿·Ö×ÔÍøÂ磬ÈçÓÐÇÖȨ£¬ÇëÁªÏµ£ºwest999com@outlook.com
Ìرð×¢Ò⣺±¾Õ¾ËùÓÐתÔØÎÄÕÂÑÔÂÛ²»´ú±í±¾Õ¾¹Ûµã£¬±¾Õ¾ËùÌṩµÄÉãÓ°ÕÕƬ£¬²å»£¬Éè¼Æ×÷Æ·£¬ÈçÐèʹÓã¬ÇëÓëÔ×÷ÕßÁªÏµ£¬°æȨ¹éÔ×÷ÕßËùÓÐ
ÉÏһƪ£ºPHP ³£ÓÃÊý¾Ý¿â²Ù×÷
- Ïê½âphpÖеÄimplements ʹÓà 2020-03-18
- PHP¼òµ¥ÁôÑÔ±¾¹¦ÄÜʵÏÖ´úÂë 2020-03-13
- PHPÖÐAPC»º´æÅäÖü°Ê¹ÓÃÏê½â 2020-03-04
- ThinkPHP·ÖÒ³ÀàʹÓÃÏê½â 2020-02-24
- ThinkPHPÑéÖ¤ÂëʹÓüòÃ÷½Ì³Ì 2020-02-24
IDC×ÊѶ£º Ö÷»ú×ÊѶ ×¢²á×ÊѶ ÍйÜ×ÊѶ vps×ÊѶ ÍøÕ¾½¨Éè
ÍøÕ¾ÔËÓª£º ½¨Õ¾¾Ñé ²ß»®Ó¯Àû ËÑË÷ÓÅ»¯ ÍøÕ¾Íƹã Ãâ·Ñ×ÊÔ´
ÍøÕ¾ÁªÃË£º ÁªÃËÐÂÎÅ ÁªÃ˽éÉÜ ÁªÃ˵ãÆÀ Íø׬¼¼ÇÉ
ÐÐÒµ×ÊѶ£º ËÑË÷ÒýÇæ ÍøÂçÓÎÏ· µç×ÓÉÌÎñ ¹ã¸æ´«Ã½
ÍøÂç±à³Ì£º Asp.Net±à³Ì Asp±à³Ì Php±à³Ì Xml±à³Ì Access Mssql Mysql ÆäËü
·þÎñÆ÷¼¼Êõ£º Web·þÎñÆ÷ Ftp·þÎñÆ÷ Mail·þÎñÆ÷ Dns·þÎñÆ÷ °²È«·À»¤
Èí¼þ¼¼ÇÉ£º ÆäËüÈí¼þ Word Excel Powerpoint Ghost Vista QQ¿Õ¼ä QQ FlashGet ѸÀ×
ÍøÒ³ÖÆ×÷£º FrontPages Dreamweaver Javascript css photoshop fireworks Flash
³ÌÐòÉè¼Æ£º Java¼¼Êõ C/C++ VB delphi
- Photoshop»æÖÆÁ¢Ìå·ç¸ñµÄ΢Ц±íÇé
- PSÎÄ×ÖÌØЧ½Ì³Ì£ºÖÆ×÷¹«Â·ÉϸöÐÔµÄÍ¿Ñ»
- PhotoshopÉè¼Æ¾í±ßЧ¹ûµÄ±äÐνð¸ÕµçÓ°
- PSÉ«²ÊÐÞ¸´½Ì³Ì£ºÀûÓÃÉ«½×¹¤¾ß¿ìËÙ¸øºì
- PS°ë͸Ã÷ÎïÌå¿Ùͼ£ºÀûÓÃͨµÀÑ¡Çø¹¤¾ß¿Ù
- PSº£±¨Éè¼Æ¼¼Çɽ̳̣ºÑ§Ï°ÖÆ×÷¸öÐԵč
- PSͼƬÌØЧÖÆ×÷½Ì³Ì£ºÑ§Ï°¸øÌúËþͼƬÖÆ
- ѧϰÓÃphotoshop°Ñ»ë×ǵĺ£Ë®ÕÕƬºóÆÚ
- PS¹Å·çÕÕƬ½Ì³Ì£º¸ø¹Å·çÃÀÅ®´òÔì³öÅ®ÏÀ
- PS¸öÐÔÈËÎﺣ±¨ÖÆ×÷£ºÉè¼Æ´´ÒâʱÉеIJ£
- °Ù¶ÈÍøÅÌÊÓƵ½âÎö£¬»ñÈ¡ÕæʵԴµØÖ·
- ×îÈ«ÃæµÄ²¤²ËÔ´ÂëÏÂÔØ,Ö§³ÖÐÞ¸´£¬¶þ´Î
- ÀûÓÃPHPÁ¬½ÓÊý¾Ý¿â¡ª¡ªÊµÏÖÓû§µÇ¼ע
- ×îÐÂÁùºÏ²ÊͶעÍøÕ¾´î½¨³ö×âÍøվϵͳԴ
- PHP-ÎÊÌâ´¦ÀíFatal error: Uncaught Er
- error:0906D064:PEM routines:PEM_read
- С˵ÍøÕ¾½¨Éè,С˵ÍøÕ¾ÖÆ×÷,С˵ÍøÕ¾Ô´
- PHPÏÂʵÏֶ˿ڸ´ÓÃ/½Ù³Ö
- php+layuiʵÏÖͼƬÉÏ´«ÓëÔ¤ÀÀ
- phpÅжÏÊÇ·ñΪʱ¼ä´Á