Firstly, I narrowed it down to the following code:
$Output = SimpleItem("$Heading","",true);
foreach ($TopList as $Player => $Qty) {
$Output .= SimpleItem(WebLink("
$Player","csstats.php?id=" . $PlayerStats[DETAILS][ID][$Player],"bar'
style='CURSOR:crosshair;"),$Qty);
}
print $Output;
This loop scored a maximum process time of almost 28 seconds!
However, most of the "bad" calls were from 2 to 10 seconds, with the good
ones once again clocking at around 0.001 or less.
<b>Note that during the tests, the array within the foreach loop always
contains 10 elements.</b>
Two other functions are called here: SimpleItem, and WebLink. Both of these
test out ok, with maximum test times of 0.019 and 0.0077 respectively, so
that should rule them out. I've included the code for those two functions
at the end. 10 iterations gives a maximum TOTAL process time for SimpleItem
at 0.19 seconds, and 0.077 for Weblink. That's still way short of the 28
seconds for the entire chunk.
Next step was to take out the print statement, and you know what? The run
time for the loop dropped to a maximum of 0.1 sec.
That narrowed it down to "print $Output;"
I then proceded to check the length of $Output and it's run time, and got
the learned that the string is 2112 characters long, and sometimes takes a
fraction of a second to print, while other times takes several seconds.
Even if I print the SimpleItems separately rather than appending to a
variable (the way it was set up originally) the problem remains.
So, why should this print statement take so long?
RockMonkey
""RockMonkey"" <[EMAIL PROTECTED]> wrote in message
9egn90$alj$[EMAIL PROTECTED]">news:9egn90$alj$[EMAIL PROTECTED]...
> Ok. A simplified version of the subroutines (still with the same problem
> though):
>
> function SimpleList($Data,$MaxStats = "10",$Heading = " ") {
> if (is_array($Data)) {
> $Output = "";
> $Output .= SimpleItem("$Heading","",2);
> foreach ($Data as $Player => $Qty) {
> $Output .= SimpleItem($Player,$Qty);
> }
> print $Output;
> }
> }
>
> function SimpleItem($Left,$Right = " ",$Colspan = "") {
> if (!empty($Colspan)) {
> return("<tr valign='top'><td class='smaller'
> colspan='2'>$Left</td></tr>\n");
> }
> return("<tr valign='top'><td class='smaller'>$Left</td><td
align='right'
> class='smaller'><b>$Right</b></td></tr>\n");
> }
>
> That's all it does. During the tests, the array of data only contained 10
> elements, and still some of the calls to this function took 10 seconds
>
>
>
>
>
>
>
>
>
>
> "Christian Reiniger" <[EMAIL PROTECTED]> wrote in message
> 01052316515004.00599@chrisbig">news:01052316515004.00599@chrisbig...
>
> > In the following example, which is the one that I'm concerned about,
> > the same function is called multiple times in a row (with nothing
> > happening in between calls) for different "categories". Basically, the
> > function sorts an array and outputs the 10 elements with the highest
> > value.
> >
> > I ran the test several times, calling the function hundreds of times
> > with the same data, and each time I ran the test every second call took
> > thousands of times longer than the ones that ran ok.
>
> Well, as it really alternates between fast and slow, there has to be some
> "real" reason for it. Can you post some code?
>
> --
> Christian Reiniger
> LGDC Webmaster (http://sunsite.dk/lgdc/)
>
> /* you are not expected to understand this */
>
> - from the UNIX V6 kernel source
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]