PHP Profiling
- 16. 옪핊잏
푾읺쁢쫂
$start = microtime();
// 측정하려는 코드
$end = microtime();
$duration = $end - $start;
원시적이다. 이러지맙시다.
$startMem = memory_get_usage();
// 측정하려는 코드
$endMem = memory_get_usage();
$memoryUsage = $end - $start;
- 28. 9EFCVH
TJODF
QIQFYUFOTJPO
샎헏핆1)1싢쩒밓
싢쩒밓
옪핊잏믾쁳헪뫃
IUUQYEFCVHPSH
삲퍟쮾펂많짾쇦몮핖픚
8FC(SJOE
,$BDIF(SJOE
8JO$BDIF(SJOE
1)14UPSN슿
- 34. 9EFCVH컲
$ pecl install xdebug
$ vi php.ini
zend_extension = xdebug.so
xdebug.profiler_enabled = 0 # 상시 프로파일링 설정
xdebug.profiler_append = 1 # 측정데이터 누적 설정
xdebug.profiler_enable_trigger = 1 # XDEBUG_PROFILE 사용설정
xdebug.profiler_output_dir = /tmp/xdebug # 파일 저장 경로
- 36. 9)1SPG컲
$ pecl install channel://pecl.php.net/xhprof-0.9.4
$ vi php.ini
extension = xhprof.so
xhprof.output_dir = /tmp/xhprof
- 38. 쪒솒픦1)1
QIQJOJ펞컪BVUP@QSFQFOE@GJMF
BVUP@BQQFOE@GJMF컲헣픒칺푷졂읺
// header
if (extension_loaded('xhprof')) {
include_once 'php/xhprof_lib/utils/xhprof_lib.php';
include_once 'php/xhprof_lib/utils/xhprof_runs.php';
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
}
// footer
if (extension_loaded('xhprof')) {
$profiler_namespace = 'profiler';
$xhprof_data = xhprof_disable();
$xhprof_runs = new XHProfRuns_Default();
$run_id =
$xhprof_runs-save_run($xhprof_data,$profiler_namespace);
}
9)1SPG컲
- 40. 캦
?PHP
function test()
{
$obj = new stdClass();
$obj-string = 'Hello';
repeat($obj);
for($i=3000; $i1; $i--) {
$obj-string .= 'Hello';
}
free($obj);
for($i=3000; $i1; $i--) {
$obj-string .= 'Hello';
}
echo $obj-string;
}
?PHP
function repeat($obj)
{
$obj-string = str_repeat($obj-string, 15000);
}
function free($obj)
{
unset($obj-string);
}
- 44. function test()
{
$obj = new stdClass();
$obj-string = 'Hello';
repeat($obj);
for($i=3000; $i1; $i--) {
$obj-string .= 'Hello';
}
free($obj);
for($i=3000; $i1; $i--) {
$obj-string .= 'Hello';
}
echo $obj-s;
}
$BMMT
- 45. function test()
{
$obj = new stdClass();
$obj-string = 'Hello';
repeat($obj);
for($i=3000; $i1; $i--) {
$obj-string .= 'Hello';
}
free($obj);
for($i=3000; $i1; $i--) {
$obj-string .= 'Hello';
}
echo $obj-s;
}
$start = microtime();
*ODMVTJWF8BMM5JNF
쿦픦홓욚킪맏쿦픦킪핟킪맏
FOETUBSU
$end = microtime();
- 47. function test()
{
$obj = new stdClass();
$obj-string = 'Hello';
repeat($obj);
for($i=3000; $i1; $i--) {
$obj-string .= 'Hello';
}
free($obj);
for($i=3000; $i1; $i--) {
$obj-string .= 'Hello';
}
echo $obj-s;
}
$start = memory_get_usage();
*ODMVTJWF.FN6TF
쿦홓욚킪옪켆큲픦젢졶읺칺푷얗
쿦킪핟킪옪켆큲픦젢졶읺칺푷얗
FOETUBSU
$end = memory_get_usage();
$start
$end
- 49. *ODMVTJWF1FBL.FN6TF
쿦홓욚킪옪켆큲픦젢졶읺칺푷얗
쿦킪핟킪옪켆큲픦젢졶읺칺푷얗
FOETUBSU
function test()
{
$obj = new stdClass();
$obj-string = 'Hello';
repeat($obj);
for($i=3000; $i1; $i--) {
$obj-string .= 'Hello';
}
free($obj);
for($i=3000; $i1; $i--) {
$obj-string .= 'Hello';
}
echo $obj-s;
}
$start = memory_get_peak_usage();
$end = memory_get_peak_usage();
$start
$end