我如何才能说出多个(都做同样的工作)中的哪一个类执行得更快?有没有软件来衡量这一点?
发布于 2009-07-29 13:30:15
为了更快,我这样做(用PHP):
$startTime = microtime(true);
doTask(); // whatever you want to time
echo "Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n";
您也可以使用像http://xdebug.org/这样的分析器。
发布于 2015-07-30 22:02:46
我做了一个简单的计时类,可能对某些人有用:
class TimingHelper {
private $start;
public function __construct() {
$this->start = microtime(true);
}
public function start() {
$this->start = microtime(true);
}
public function segs() {
return microtime(true) - $this->start;
}
public function time() {
$segs = $this->segs();
$days = floor($segs / 86400);
$segs -= $days * 86400;
$hours = floor($segs / 3600);
$segs -= $hours * 3600;
$mins = floor($segs / 60);
$segs -= $mins * 60;
$microsegs = ($segs - floor($segs)) * 1000;
$segs = floor($segs);
return
(empty($days) ? "" : $days . "d ") .
(empty($hours) ? "" : $hours . "h ") .
(empty($mins) ? "" : $mins . "m ") .
$segs . "s " .
$microsegs . "ms";
}
}
使用:
$th = new TimingHelper();
<..code being mesured..>
echo $th->time();
$th->start(); // if it's the case
<..code being mesured..>
echo $th->time();
// result: 4d 17h 34m 57s 0.00095367431640625ms
发布于 2009-07-30 00:16:56
我最近一直在用XHProf,http://pecl.php.net/package/xhprof。它最初是由Facebook开发的,它有一个不错的web界面。
https://stackoverflow.com/questions/1200214
复制相似问题