NYCPHP Meetup

NYPHP.org

[nycphp-talk] testing a theory

tedd tedd at sperling.com
Wed Feb 7 11:44:28 EST 2007


At 11:20 AM -0500 2/7/07, Aaron Fischer wrote:
>How would one test something like this?  Testing for performance is 
>something I would like to start doing but I don't know where/how to 
>start.
>
>-Aaron

-Aaron:

Ahhh, now that's a different critter.

First, your question deals with time, so a timer is in order. I use this:

<?php
$starttime = microtime();
$startarray = explode(" ", $starttime);
$starttime = $startarray[1] + $startarray[0];
?>

Then, I place here what I want to test, such as a loop to test your 
first snippet:

<?php
$content = "this is the start of a bunch of lines";
$content .= "another line";
$content .= "yet another";

for ($i = 1; $i <= 1000; $i++)
    {
    echo $content;
    }
?>

Then I finish the timing with:

<?php
$endtime = microtime();
$endarray = explode(" ", $endtime);
$endtime = $endarray[1] + $endarray[0];
$totaltime = $endtime - $starttime;
$totaltime = round($totaltime,5);
echo "<br/><br/><br/>This test took $totaltime seconds.";
?>

That will tell me how much time your first snippets took to run 1000 
times. Now, do the same with the second one and find out for yourself 
if there is any difference between the two. I suspect if there is any 
difference, it will be in your second set of code because it calls 
echo() more and thus takes more time to execute. In addition, I also 
suspect that you will have to increase the iterations to something 
greater than 1000 to see any noticeable difference in either, but 
that's a guess.

Have fun testing.

Cheers,

tedd
-- 
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com



More information about the talk mailing list