Script que calcula o tempo que a página levou para ser processada.
Deve-se incluir o arquivo exec_time.php no início do script, chamar a função startExec() e no final do script chamar a função endExec().
/*
*
* @file: exec_time.php
*
* @author: Jefferson Luis
*
* @date: 07/12/2011
*
* @description: calculates the time of execution of a script
*
* @use: include this file in the top of the script, call function startExec() and
* the end of script call the function endExec().
*
* Function endExec print results in the screen.
*
*/
global $time;
/* Get current time */
function getTime(){
$microtime = explode(" ", microtime());
$time = $microtime[0] + $microtime[1];
return $time;
}
/* Calculate start time */
function startExec(){
global $time;
$time = getTime();
}
/*
* Calculate end time of the script,
* execution time and print
* result in the screen
*/
function endExec(){
global $time;
$finalTime = getTime();
$execTime = $finalTime - $time;
echo 'Execution time: ' . number_format($execTime, 6) . ' ms';
}
exemplo de uso:
include('exec_time.php');
startExec();
for($i=0;$i<1000;$i++){
}
endExec();
