Location: PHPKode > scripts > PHP Script Timer > php-script-timer/PHP_Script_Timer_doc.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>PHP Script Timer documentation</title>
  <meta name="author" content="Paul Postuma, Ars Informatica">
  <meta name="language" content="english">
  
  <style type="text/css">
	a.generic:link {color: #0000FF;}
	a.generic:visited {color: #800080;text-decoration:underline;}
	a.generic:active {color: #FF0000;text-decoration:underline;}
	a.generic:hover {color: #0000FF;text-decoration:underline;}
	
	.main_text {font:8pt Verdana}
	.code {width:580px;color:#006699}
  </style>
</head>

<body>
<a href="http://www.ars-informatica.ca" target="_top"><img src="resources/AI_logo_med.gif" style="position:absolute;left:56px;top:31px;z-index:1" border="0" alt="Ars Informatica"></a>

<div style="position:absolute;left:38px;top:91px">
<table style="width:920px;z-index:0;border-color:#bbbbbb;vertical-align:top;text-align:left" border="6" cellpadding="0" cellspacing="0">
    <tr style="height:24px;background-color:#515c9a;font:bold 10pt Verdana;color:#ffffff;text-align:right;width:160px;padding-right:20px">
      <td>May 30, 2006</td>
    </tr>
    <tr>
      <td valign="top"><div style="position:relative;width:870px;padding:20px"><p>Code choking your server's CPU? Site visitors clicking away because your page is taking too long to respond? Do you know?</p><p>PHP typically executes very quickly, though some code just plods. Retrieving and parsing remote files, image manipulations, multiple complex SQL queries, can grind down your site. Use PHP Script Timer to identify your bottlenecks.</p><p>For example, you want to retrieve and parse a remote RSS news feed. Do you use a locally cached file copy if it's current enough? Do you not bother, and just use the remote feed each time? Does it matter?</p><p>Using my walRuSS.php RSS feed script, and a remote feed:</p><pre class="code">Script execution over 10 loops averages 1.55419661999 seconds<br />Fastest: 1.07788205147 seconds<br />Slowest: 3.7918651104 seconds</pre><p>Now, exact same script, exact same feed, but cached:</p><pre class="code"><p>Script execution over 10 loops averages 0.0444237470627 seconds<br />Fastest: 0.0355970859528 seconds<br />Slowest: 0.0772120952606 seconds</p></pre><p>Surprised? I was. And I use a local cache file rather than the remote feed, if the cache file is 'fresh' enough.</p><p>PHP Script Timer is short, simple, and very easy to use. First, reference the script:</p><pre class="code"><p>include 'PHP_script_timer.php';</p></pre><p>Next, call the timing script immediately before the code you wish to time:</p><pre class="code">$timing_loops = 1;<br />for ($current_loop = 0; $current_loop &lt; $timing_loops; $current_loop++) {<br />$time_start = microtime_float();</pre><p>And at the end of the code you're timing:</p><pre class="code"><p>$timing[] = microtime_float() - $time_start;<br />}<br />timing($timing);</p></pre><p>To run more the timing loop more then once, and calculate fastest, slowest and average execution times, simply specify 2 or more $timing_loops.</p><p>Customize your output further by changing the report_timing &lt;STYLE&gt; tag, or alter the HTML output code as you see fit.</p><p>Enjoy!</p><p>This PHP script is released under the terms of the GNU General Public License, i.e. free for you to use, modify, and even redistribute under the terms of this license - see <a href="http://www.gnu.org/copyleft/gpl.html">http://www.gnu.org/copyleft/gpl.html</a> for further details.</p><p><a title="PHP Script Timer source code" href="PHP_script_timer_source_code.htm"><img style="MARGIN-BOTTOM: -10px" alt="magnifier icon" hspace="10" src="resources/magnifier.gif" align="left" border="0" /></a>view <a title="PHP Script Timer source code" href="PHP_script_timer_source_code.htm">PHP Script Timer source code</a><br clear="all" /></p><p /></div>
      <p>
      </td>
    </tr>
</table>

<p>Copyright &copy; 2006 <a href="http://www.ars-informatica.ca" target="_top">Ars Informatica</a>. All Rights Reserved.

<p>&nbsp;</div>

<div style="position:absolute;top:87px;left:80px;width:720px;z-index:1;color:#FDEC2D;font:bold italic 20pt "times new roman",times,serif">PHP Script Timer Documentation</div>
Return current item: PHP Script Timer