parse times?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

parse times?

Post by malcolmboston »

i have heard alot of people talking about how fast there scripts parse in like 0.14 seconds etc.

just wanted to ask how you can find out?
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

quite simple...

lets say this is a big script:

Code: Select all

<?php
$start_time = time();
//lines of code
//lines of code
//lines of code
//lines of code
//lines of code
//lines of code
$end = round(time() - $start_time, 3);
echo "Page parsed in ". $end." secs";
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

To get the microseconds as well try this from the PHP manual:
php.net/microtime

Code: Select all

<?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";

?>
Mac
Post Reply