php中怎么使用yield提升性能,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
demo1.php
运行结果如下:
49993 squared is 2499300049
49994 squared is 2499400036
49995 squared is 2499500025
49996 squared is 2499600016
49997 squared is 2499700009
49998 squared is 2499800004
49999 squared is 2499900001总共占用的内存大小为:1.28 mb
总共占用的时间为:5秒demo2.php
$i*$i; } } foreach(squares(0,50000) as $n=>$square ){ echo $n.' squared is '.$square.PHP_EOL; } $endTime = time(); $useTime = $endTime-$startTime; $endMemory = memory_get_usage(); $useMemory = $endMemory-$startMemory; echo "总共占用的内存大小为:".convert($useMemory).PHP_EOL; echo "总共占用的时间为:".$useTime.'秒'.PHP_EOL;运行demo2.php结果如下:
49988 squared is 2498800144
49989 squared is 2498900121
49990 squared is 2499000100
49991 squared is 2499100081
49992 squared is 2499200064
49993 squared is 2499300049
49994 squared is 2499400036
49995 squared is 2499500025
49996 squared is 2499600016
49997 squared is 2499700009
49998 squared is 2499800004
49999 squared is 2499900001
总共占用的内存大小为:32 b
总共占用的时间为:5秒关于php中怎么使用yield提升性能问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。
本文题目:php中怎么使用yield提升性能-创新互联
文章URL:http://tyjierui.cn/article/dhsodg.html