(转载自CSDN)
方法一:
//计时开始 runtime(); //执行查询 mysql_query($sql); //计时结束. echo runtime(1); //计时函数 function runtime($mode=0) { static $t; if(!$mode) { $t = microtime(); return; } $t1 = microtime(); list($m0,$s0) = explode(" ",$t); list($m1,$s1) = explode(" ",$t1); return sprintf("%.3f ms",($s1+$m1-$s0-$m0)*1000); }
方法二:
$t1=microtime(true); mysql_query($sql); echo microtime(true)-$t1;