This is a discussion on Newbie question about <?= ?> within the PHP General forums, part of the PHP Programming Forums category; Satyam wrote: > for ($x=0;$x<1000;$x++) { > echo ' <tr><td>X is ' , $...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Satyam wrote:
> for ($x=0;$x<1000;$x++) { > echo ' <tr><td>X is ' , $x , '</td></tr>'; > } This seems to be a hair faster. I extended the test to 10000 requests (still concurrency 10) to make the test a little more reproducible: echo str,var,str did 604.65 requests a second where <tr><td><?= $x ?></td></tr> did 599.63 requests a second. I also tried echo str . var . str, and it came in at about 584.55 requests a second. printf("str %i str",var) came out at 547.01 requests a second and printf("str %s str",var) was only 452.03 requests a second. > Can you try and time that one so we have comparable results? This one > should be second best: > > for ($x=0;$x<1000;$x++) { > echo "<tr><td>X is $x</td></tr>"; > } Approximately 330 (?!) requests a second for that one. > Back again to what would be 'longer', well, in your example, the whole > header, up to the loop itself should be faster if sent out of PHP. > Likewise, you could echo $buffer right after the loop, drop out of PHP > and send the footer as plain HTML. This, of course, is harder to time > since it happens only once. I admit though that I did time the > options I listed and on the 'dropping in and out of PHP' I'm relying > on the PHP manual ( see > http://www.php.net/manual/en/language.basic-syntax.php, the first > paragraph after the examples) and the source of the lexical scanner, > which supports that, though your numbers do contradict it. Interesting. I'm not sure that my results would count as contradictory - I'm running APC which would likely throw performance related numbers out of whack as compared to out-of-the-box PHP. Because of that, I wouldn't recommend anyone take my numbers too seriously - they're just an example taken from my server: 1.8 GHz SMP/1G/RAID5/Linux 2.6.17.7/Apache 2.2.3/PHP 5.1.6/APC 3.0.12p2. Anyone else's results would probably vary widely. jon |
|
|||
|
How bored am I?
This bored: http://dev.stut.net/phpspeed/ Server is running PHP 5.1.2 (really should upgrade that) with no caches of any sort. -Stut |
|
|||
|
At 4:56 PM +0100 9/11/06, Stut wrote:
>How bored am I? > >This bored: http://dev.stut.net/phpspeed/ > >Server is running PHP 5.1.2 (really should upgrade that) with no >caches of any sort. > >-Stut Which begs the question, does it make much of a difference? (not you being bored, but the rather speed concers). With all the things out there that can slow your browsers reaction time in presenting some result, does a couple of seconds count much in the over all scheme of things? I know, purest will say that they want to make whatever they do as fast as possible, but is that time to make it faster be better spent elsewhere? We used to have to worry about the size of our strings, but now we can place the kjv of the bible in one. So, what's the point of counting characters in strings now? I suspect at some point, probably soon, speed isn't going to matter much. Opinions? tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |
|
|||
|
I admit I'm totally surprised about the buffered results. Nevertheless, may
I sugest you add the following to the series of tests?: <h3>Using line-by-line single-quoted echo<br/>with comma separated arguments</h3> <?php $start = mt(); print '<table style="display:none;" id="table2a">'; for ($x = 0; $x < $iterations; $x++) { echo '<tr><td>X is</td><td>',$x,'</td></tr>'; } print '</table>'; $duration = mt() - $start; print '<p>Took '.number_format($duration, 4).' seconds</p>'; ?> <p>» <a id="table2alink" href="#" onclick="document.getElementById('table2a').style. display='block'; document.getElementById('table2alink').style.displ ay='none';return false;"> Reveal output</a></p> There seems to be one thing rarely anybody remembers, echo admits multiple arguments, and as the numbers will show, (or at least they do in my machine), they are the second best option. Satyam ----- Original Message ----- From: "Stut" <stuttle@gmail.com> To: "Jon Anderson" <jon@gamingsolutions.ca> Cc: "Satyam" <Satyam@satyam.com.ar>; <php-general@lists.php.net> Sent: Monday, September 11, 2006 5:56 PM Subject: Re: [php] Re: Newbie question about <?= ?> > How bored am I? > > This bored: http://dev.stut.net/phpspeed/ > > Server is running PHP 5.1.2 (really should upgrade that) with no caches of > any sort. > > -Stut > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > |
|
|||
|
Satyam wrote:
> I admit I'm totally surprised about the buffered results. > Nevertheless, may I sugest you add the following to the series of tests?: > > <h3>Using line-by-line single-quoted echo<br/>with comma > separated arguments</h3> > <snip> > > There seems to be one thing rarely anybody remembers, echo admits > multiple arguments, and as the numbers will show, (or at least they do > in my machine), they are the second best option. Done, but again it doesn't seem to make any significant difference to the performance. -Stut |
|
|||
|
tedd wrote:
> At 4:56 PM +0100 9/11/06, Stut wrote: >> How bored am I? >> >> This bored: http://dev.stut.net/phpspeed/ >> >> Server is running PHP 5.1.2 (really should upgrade that) with no >> caches of any sort. >> >> -Stut > > Which begs the question, does it make much of a difference? (not you > being bored, but the rather speed concers). > > With all the things out there that can slow your browsers reaction > time in presenting some result, does a couple of seconds count much in > the over all scheme of things? > > I know, purest will say that they want to make whatever they do as > fast as possible, but is that time to make it faster be better spent > elsewhere? We used to have to worry about the size of our strings, but > now we can place the kjv of the bible in one. So, what's the point of > counting characters in strings now? > > I suspect at some point, probably soon, speed isn't going to matter much. > > Opinions? I would have to agree. Having watched the server CPU load while playing with this test script it would appear that the performance can be skewed a lot more by that than by the method you use for squidging out the output. As a curiosity I've also added a test using <?php print $x; ?> and bizarrely that appears to be slightly faster than <?=$x?>. Weird. -Stut |
|
|||
|
Jon Anderson wrote:
> Stut wrote: >> How bored am I? >> >> This bored: http://dev.stut.net/phpspeed/ >> >> Server is running PHP 5.1.2 (really should upgrade that) with no >> caches of any sort. > Just looking through the source, could you try changing the first > example to put the output all on one line? It's the only one that does > the row output on multiple indented lines - I'm kind of curious what > effect (if any) that has on the results. Done. Doesn't seem to make a difference - I didn't expect it to. > I also tried this on my own server. With the opcode cache, the results > seem to be the inverse of yours without. I would have been surprised if an opcode cache had made a huge difference. I don't think the Zend Engine is intelligent enough to compile the various different tests to the same set of opcodes - but I could be wrong. I'm still quite new to the PHP internals. > Also, with either server, the first three results seem to vary wildly, > but the last two always seem to come out the same. I'm not sure why > that is... As I said in another post, the performance varies wildly with the load on the server. -Stut |
|
|||
|
----- Original Message -----
From: "Stut" <stuttle@gmail.com> To: "Satyam" <Satyam@satyam.com.ar> Cc: <php-general@lists.php.net> Sent: Monday, September 11, 2006 6:32 PM Subject: Re: [php] Re: Newbie question about <?= ?> > Satyam wrote: >> I admit I'm totally surprised about the buffered results. Nevertheless, >> may I sugest you add the following to the series of tests?: >> >> <h3>Using line-by-line single-quoted echo<br/>with comma separated >> arguments</h3> >> <snip> >> >> There seems to be one thing rarely anybody remembers, echo admits >> multiple arguments, and as the numbers will show, (or at least they do in >> my machine), they are the second best option. > > Done, but again it doesn't seem to make any significant difference to the > performance. > > -Stut > > When I run those tests locally, the numbers are totally different and the performance of one over the other comes out far clearer. I can only assume that the numbers in the test run in a remote server are so much influenced by the ability of the server to push out the characters into the output stream that the processing time itself is of very little relevance. This table shows the numbers for the different tests as run on my machine, locally (where output streaming is irrelevant) and run from your site: Using <?=$x?> Took 0.2801 seconds Took 3.5937 seconds Using <?php print $x; ?> Took 0.3286 seconds Took 5.2654 seconds Using line-by-line single-quoted print: Took 0.1215 seconds Took 3.2256 seconds Using line-by-line single-quoted echo with comma separated arguments Took 0.2542 seconds Took 3.2220 seconds Using line-by-line double-quoted print Took 0.1782 seconds Took 3.3129 seconds Using buffered single-quoted print Took 0.0277 seconds Took 3.3077 seconds Using buffered double-quoted print Took 0.2038 seconds Took 3.3012 seconds It would seem that it takes about 3 seconds to push those bytes into the network, the actual processing times get completely masked behind a simple glitch in the throughput of the communication line. While the differences on the rightmost column (except for the second one, which is way off) are no more than 5%, in the middle column the differences are up to 10 to 1. But then there is that second row, which is so much higher and it is so in both columns. Unfortunately, I cannot make much sense about all this. I don't get it. Nevertheless, something it is clear is that buffering all the output first and then pushing it out all at once seems to beat them all, specially using single quoted strings. Run locally, the differences are amazing! Satyam |
|
|||
|
At 5:36 PM +0100 9/11/06, Stut wrote:
>tedd wrote: >>Opinions? > >I would have to agree. Having watched the server CPU load while >playing with this test script it would appear that the performance >can be skewed a lot more by that than by the method you use for >squidging out the output. > >As a curiosity I've also added a test using <?php print $x; ?> and >bizarrely that appears to be slightly faster than <?=$x?>. > >Weird. My guess would be that it's in the interpreter -- the look-up for "<?" as compared to "<?php" may be delayed because of checking for the short-tag option-on, or something similar. But, I admittedly don't know. However, I strongly suspect that drawing to the screen will take longer than executing any "=" or "print" statement anyway. So regardless of the time saved in computation, the delivery would appear identical. It reminds me of the "hurry-up and wait" saying we had in the Army some 50 years back. tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |