[Typo3-dev] char <-> string -> overhead -> speed
Peter Russ
peter.russ at 4dfx.de
Sun Sep 26 22:45:11 CEST 2004
Michael Johnston wrote:
> Unfortunately, there is only one way to optimize effectively. That is to
> profile production code & find the slow parts then use theory,
> intuition, but mostly trial and error to make the slow parts less slow.
>
> Tests like the one you wrote are far too simplistic to be useful at all.
> Want proof? Run it this way:
>
> <?php
> $imax=5000000;
> $tStart=time();
> $nl = "\n";
> $bob = 'mary';
> for($i=0;$i<$imax;$i++) $stringString="TextTextTextText\nnewLine$bob$bob";
> $endTime=time()-$tStart;
> echo "string=$endTime.<br>";
> $tStart=time();
> for($i=0;$i<$imax;$i++)
> $stringChar='TextTextTextText'.$nl.'newLine'.$bob.$bob;
> $endTime=time()-$tStart;
> echo "chr=$endTime.<br>";
> ?>
>
> ....oops! now string takes longer. Why? probably because it's
> interpolation of variables that is time consuming, not interpolation of
> escaped characters.
>
> If you're going to write tests to get an idea of how to pre-optimize
> your code, you'd better write lots of different tests, or you may
> accidentally come up with such a misleading result that you end up
> DE-optimizing your code.
>
> In our case, on a site with many custom content elements & plugins, we
> quickly changed a bunch of interpolated strings that were in loops to be
> non-interpolated and got a nice increase in speed. As measured by
> profiling the actual site on the actual machine, before and after.
>
> Cheers,
> Michael Johnston
> Planetactive
Thanks for your reply.
The main intention for that question was NOT to start a discussion about
BENCHMARKING. Sorry if that was not that clear!
The question raised when I used the extdeveval extension with the option
of transfering all " to '. Because a "\n"!='\n'.
So there should be a benefit to transfer all strings to char-arrays. For
Java I know that is might outperform a string. But for PHP I had no
indication that there is a benefit. But perhaps I'm missing some
articles/source about PHP optimization.
So how would this perform "TextTextTextText\n".$bob.$bob ?
I'm interested in the advantages of doing/programming things in one way
or another. Any hint is highly appricated.
Regs. Peter.
More information about the TYPO3-dev
mailing list