March 1, 200917 yr Insert at the beginning of page PHP Code: $m_time = explode(" ",microtime()); $m_time = $m_time[0] + $m_time[1]; $loadstart = $m_time; insert at the end of page PHP Code: $m_time = explode(" ",microtime()); $m_time = $m_time[0] + $m_time[1]; $loadend = $m_time; $loadtotal = ($loadend - $loadstart); echo "<small><em>Generated page in ". round($loadtotal,3) ." seconds</em></small>";
March 1, 200917 yr I see you're not asking a question but posting some code others might find helpful - so thanks One suggestion I'd make is to only do the explodes later - the reason being that if you are interesting in microsecond granularity, there's always a chance the explode() themselves will take extra processing time and upset the results. Therefore I'd make these ever-so-slight changes (and wrap them in functions I can include and call in every page): <?php /* loadtimes.php */ function loadtime() { return microtime(); // this doesn't work on all platforms (see man) so alternatives may be used there } function loadend($loadstart) { $loadend = loadtime(); /* Now do all the processing here, after having taken the timings */ $m_time = explode(" ",loadstart); $loadstart = $m_time[0] + $m_time[1]; $m_time = explode(" ",loadend); $loadend = $m_time[0] + $m_time[1]; $loadtotal = $loadend - $loadstart; echo "<p class=\"loadtime\">Generated page in ". round($loadtotal,3) ." seconds</p>"; } ?> Then in each PHP page: <?php include "loadtimes.php"; $loadstart = loadtime(); // rest of page loadend($loadstart); ?> Really just a minor modification to avoid effects which are probably negligible in comparison to the rest of your page anyway, and make the code reusable.
March 1, 200917 yr Author I see you're not asking a question but posting some code others might find helpful - so thanks One suggestion I'd make is to only do the explodes later - the reason being that if you are interesting in microsecond granularity, there's always a chance the explode() themselves will take extra processing time and upset the results. Therefore I'd make these ever-so-slight changes (and wrap them in functions I can include and call in every page): <?php /* loadtimes.php */ function loadtime() { return microtime(); // this doesn't work on all platforms (see man) so alternatives may be used there } function loadend($loadstart) { $loadend = loadtime(); /* Now do all the processing here, after having taken the timings */ $m_time = explode(" ",loadstart); $loadstart = $m_time[0] + $m_time[1]; $m_time = explode(" ",loadend); $loadend = $m_time[0] + $m_time[1]; $loadtotal = $loadend - $loadstart; echo "<p class=\"loadtime\">Generated page in ". round($loadtotal,3) ." seconds</p>"; } ?> Then in each PHP page: <?php include "loadtimes.php"; $loadstart = loadtime(); // rest of page loadend($loadstart); ?> Really just a minor modification to avoid effects which are probably negligible in comparison to the rest of your page anyway, and make the code reusable. Thanks Connetu_C...
March 3, 200917 yr Every one else was doing it so fidgured I'd post my timer function also ///------------------------------------------ /// function to calculate parse time ///------------------------------------------ function funcParseTimer($vMarker='') { $aTmp = explode (" ", microtime ()); $vTime = $aTmp[1] + $aTmp[0]; if (!defined('RICE_PARSE_TIME')) { define('RICE_PARSE_TIME',$vTime); srand((float) $aTmp[1] + ((float) $aTmp[0] * 100000)); } else { echo '<!-- '.$vMarker,': ',round(($vTime - RICE_PARSE_TIME),4)," seconds -->\r\n"; } }
Create an account or sign in to comment