php测试代码执行时间,php debug记录程序执行时间和执行情况

/**

* debuging('dtrace'); //查看调用栈

* debuging($var); //打印$var(var_dump)

* debuging($var, 'php'); //打印$var(var_export)

* debuging($var, $echo, 2); //以json格式输出$var

* debuging(__LINE__.__CLASS);//常用于大量if语句体定位, 或者寻找程序结束点

*/

function debuging($var = '', $echo = '', $die = false, $force = false) {

static $clear;

if (0 && $clear === null) {

ob_end_flush ();

$clear = true;

}

static $d;

if (0 && empty ( $d )) {

$d = 1;

debuging ( 'dtrace' );

}

$force && $_GET ['debug'] = 1;

if (isset ( $_GET ['debug'] )) {

if ('dtrace' === $var) {

dTrace ( $die );

} elseif ($die === 2) {

header ( 'Content-type: application/json' );

echo json_encode ( $var );

} else {

echo "

\n";

if ($echo) {

echo "$echo:";

}

if ($echo === 'php')

var_export ( $var );

else

var_dump ( $var );

echo "

\n";

}

$die && die ();

}

}

function dTrace($die = false) {

try {

static $lastTime;

$lastTime or $lastTime = $_SERVER ['REQUEST_TIME'];

throw new Exception ();

} catch ( Exception $e ) {

$currTime = microtime ( true );

$totalTime = $currTime - $_SERVER ['REQUEST_TIME'];

$execTime = $currTime - $lastTime;

$lastTime = $currTime;

echo "\n


\n";

echo "execTime: $execTime s.
\n";

echo "totalTime: $totalTime s.
\n";

echo "Trace:
\n";

// echo $e->getTraceAsString() ;

// debug_print_backtrace();$die && die;

debuging ( $e->getTraceAsString (), 'php', $die );

}

}

for($i=0;$i<100000;$i++) {

$a +=$i;

}

dTrace();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值