Forum und email

microtime

(PHP 4, PHP 5)

microtime — Retorna um timestamp Unix com microsegundos

Descrição

mixed microtime ([ bool $get_as_float ] )

A microtime() retorna o timestamp atual com microsegundos. Esta função está apenas disponível em sistemas operacionais que suportam o chamda do sistema gettimeofday().

Quando chamada sem o argumento opcional, esta função retorna a string "msec sec" onde sec é o a hora atual medida em segundos desde a era UNIX (0:00:00 January 1, 1970 GMT), e msec é a parte em microsegundos. Ambas porções de string são retornadas em segundos.

Quando get_as_float é dado, e avalia para TRUE, microtime() retornará um tipo float.

Nota: O parâmetro get_as_float foi adicionado no PHP 5.0.0.

Example#1 microtime() exemplo

<?php
function getmicrotime() 

    list(
$usec$sec) = explode(" "microtime()); 
    return ((float)
$usec + (float)$sec); 


$time_start getmicrotime();
    
for (
$i=0$i 1000$i++){
    
//do nothing, 1000 times
    
}

$time_end getmicrotime();
$time $time_end $time_start;

echo 
"Did nothing in $time seconds\n";

// with PHP 5 you can do the same this way:
       
      
$time_start microtime(1);
       
      for (
$i=0$i 1000$i++){
           
// do nothing, 1000 times
      
}
       
      
$time_end microtime(1);
      
$time $time_end $time_start;
       
      echo 
"Did nothing in $time seconds\n";
?>

Veja também time().