Jump to content

Timing Scripts


Recommended Posts

Is there any way to determine the execution times of scripts? I'd really like to "profile" my script before it gets out of control. In the past, I've used run-time profilers to determine where and how much time is spent in programs I've written, with the objective of determining if new algorithms are required, or if re-arranging the code can reduce runtime and/or lower response time.


I've looked into the MySQL and PHP documents, and their respective forums, as well as TCH forums, but haven't found anything like what I want.


These scripts will be run as cron jobs - is there something available along those lines to obtain the information I need? Or, is this whole concept a thing of the past?



Link to comment
Share on other sites

It's probably a start at what I'm looking for. If you don't mind, please send me a link, or show it in this forum.


The script I wish to "profile" consists of outer and inner query loops. Within the inner loop, e-mail is generated, but not necessarily on each iteration. It would not be uncommon for the innermost code to execute millions of times.


Other RDBMS will show their query execution plans for given SQL, but I'm not aware of this facility with MySQL. Evaluating a QEP can reveal how effective indices, key selections, and table organization actually are. Honestly, I don't have formal MySQL DBA training, so there may be something I'm not aware of.


So, it's really this that I wish to evaluate, and any clues as to how to accomplish that will be appreciated.



Link to comment
Share on other sites

function get_microtime()
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = doubleval($mtime[1]) + doubleval($mtime[0]);
return ($mtime);

$time1 = get_microtime();

//all the stuff you want to time goes here

$time2 = get_microtime();

$diff = abs($time2-$time1);

From PHP Developer's Cookbook

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...