PHP 수행시간 측정

Jmnote (토론 | 기여)님의 2012년 2월 26일 (일) 21:46 판 (→‎예제 1)
  • PHP 수행시간 측정
  • PHP 속도 측정
  • PHP 속도 비교

1 수행시간 측정

<?php
function get_time() {
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}

$start = get_time();
/*
수행할 내용
*/
$end = get_time();
$time = $end - $start;
echo '<br/>'.$time.'초 걸림';
?>

2 예제 1

<!DOCTYPE html>
<meta charset="utf-8" />
<?php
function get_time() {
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}

function pow2($b, $n)
{
	$result = 1;
	for($i=0;$i<$n;$i++) {
		$result *= $b;
	}
	return $result;
}

function pow3($b, $n)
{
	if($n<2)return $b;
	return pow3($b, $n-1) * $b;
}

$start = get_time();

for($i=0;$i<100000;$i++) {
	$a = pow($i, 20);
}

$end = get_time();
$time = $end - $start;
echo '<br/>'.number_format($time,4).'초 걸림';
echo '<br/>결과값: '.$a;
?>

3 참고자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}