代码运行耗时测试函数

    function testStart(){
        ob_start();
        self::$startTime = microtime(true);
    }
    
    function testEnd(){
        self::$endTime = microtime(true);
        ob_end_clean();
        $costTime = self::$endTime - self::$startTime;
        echo 'cost time(Second):'.$costTime."<br />\n";
        //die('cost time(Second):'.$costTime."<br />\n");

    }


example:

testStart();

for($i = 0;$i < 5000;$i ++)
        {
            echo pow($i, 3),"<br />\n";
        }

testEnd();


result:

cost time(Second):0.0153968334198


你可能感兴趣的:(function,测试)