我是一個PHP編碼器。在執行code.means執行時間期間,我找不到任何方法來獲取執行多少時間。 以及代碼在執行期間使用了多少內存空間tim執行時間和內存使用的代碼
我知道PHP INI設置,但沒有顯示我的解決方案。
我怎麼能得到與編碼時間和內存空間單元。
我是一個PHP編碼器。在執行code.means執行時間期間,我找不到任何方法來獲取執行多少時間。 以及代碼在執行期間使用了多少內存空間tim執行時間和內存使用的代碼
我知道PHP INI設置,但沒有顯示我的解決方案。
我怎麼能得到與編碼時間和內存空間單元。
你可以在開始你的腳本中使用
microtime()
,並在年底。差異將是執行時間。 microtime返回微秒的時間戳足夠滿足您的需求。
我總是用
microtime()
時序,並
memory_get_usage()
內存使用,再加上我的IDE(PHPStorm)和Xdebug這使相當一些有用的信息。
http://www.php.net/manual/en/function.microtime.php 和 http://php.net/manual/en/function.memory-get-usage.php
我發現這個一個在發生器的例子。
$start_time=microtime(true);
//do something what you want to measure
$end_time=microtime(true);
echo "time: ", bcsub($end_time, $start_time, 4), "\n";
echo "memory (byte): ", memory_get_peak_usage(true), "\n";
http://php.net/manual/en/language.generators.overview.php#114136
http://stackoverflow.com/questions/2942385/php-code-execution-time – 2013-03-19 06:36:31
http://php.net/manual/en/function.memory-get-usage .php – 2013-03-19 06:38:14
[在PHP中跟蹤內存使用情況]的可能重複(http://stackoverflow.com/questions/2290611/tracking-memory-usage-in-php) – 2013-03-19 06:38:49