标签 代码段 下的文章

life by php

<?php

$days = rand(1, 9999999); //生命里有各种不测
$problems = rand(0, 9999999); //人生充满了各种问题

while ($days){ //只要活着
    $days--; //日子就要一天天走着
    (rand(0, 9999999)%2) ? $problems++ : $problems--; //或许问题总会解决
}

die(); //但总有一天你会离开
echo '时间不会给你足够的时间领悟';

PHP执行时间类

其实也就是通过microtime函数在前后个执行一下,计算时间差获取代码段的执行时间,测试效率

$runtime->stop();
echo $_b;
echo "页面执行时间: ".$runtime->spent()." 毫秒";

class runtime
{
    var $StartTime = 0;
    var $StopTime = 0;
    function get_microtime()
    {
        list($usec, $sec) = explode(' ', microtime());
        return ((float)$usec + (float)$sec);
    }

    function start()
    {
        $this->StartTime = $this->get_microtime();
    }

    function stop()
    {
        $this->StopTime = $this->get_microtime();
    }

    function spent()
    {
        return round(($this->StopTime - $this->StartTime) * 1000, 1);
    }
}

原文出自开源中国