当前位置:Gxlcms > PHP教程 > 测试代码效率

测试代码效率

时间:2021-07-01 10:21:17 帮助过:4人阅读

begin($start);
report($start);
  1. function begin(&$start) {
  2. $tmp = gettimeofday();
  3. $start = $tmp[usec];
  4. }
  5. function report($start) {
  6. $tmp = gettimeofday();
  7. $now = $tmp[usec];
  8. echo "time consuming: ";
  9. echo $now - $start;
  10. echo "
    ";
  11. }
  12. function getRandNum($length = 8) {
  13. $salt = substr(uniqid(rand()), -$length);
  14. return $salt;
  15. }
  16. $start = 0;
  17. begin($start);
  18. $str="";
  19. while (strlen($str)< 10000)
  20. {
  21. $str.=getRandNum(1);
  22. }
  23. report($start);

人气教程排行