测试代码效率
时间:2021-07-01 10:21:17
帮助过:4人阅读
begin($start); report($start);
- function begin(&$start) {
- $tmp = gettimeofday();
- $start = $tmp[usec];
- }
- function report($start) {
- $tmp = gettimeofday();
- $now = $tmp[usec];
- echo "time consuming: ";
- echo $now - $start;
- echo "
"; - }
- function getRandNum($length = 8) {
- $salt = substr(uniqid(rand()), -$length);
- return $salt;
- }
- $start = 0;
- begin($start);
- $str="";
- while (strlen($str)< 10000)
- {
- $str.=getRandNum(1);
- }
- report($start);
|