RE: is <?= good?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 5:28 PM -0700 6/11/10, Daevid Vincent wrote:
 > -----Original Message-----
 > From: Ahmed Mohsen [mailto:mrez05@xxxxxxxxx]
 >
 Hey Daevid, does this form <?php echo 'The answer is '.$answer; ?>
 improve anything in processing time or it's just for the sake of
 readability?

Technically it does have a microscopic speed increase, but unless you're
pumping out hundreds or thousands of lines (like in a loop) you most likely
won't notice it. In my code, I always try to use the proper quote marks
because I *am* dealing with huge tables of data. I've said this a hundred
times before, if you can shave off 0.001 from each row, then after 1,000
rows, you've shaved 1 second off the page time. That seems small, but that
shit adds up. Caching will help, as the page is already parsed once, so PHP
doesn't have to do the work again in many cases. To me, it's a good habbit
and costs you nothing to do.

The difference is that with " the PHP engine has to pre-process the string
and look to see if there's anything interesting it needs to do -- such as
replace any $var with their equivalents or \n or whatever else. A ' means
to use it as is, so PHP just spits it back out.

In my test comparing:

   $a = 'The answer is ' .$answer;

vs:

   $a = "The answer is $answer;"

I ran numerous test using 10,000,000 (10 million) operations each and the results never exceed 1/2 of a second difference, usually around 1/3 of a second.

I realize that servers and conditions can change the results, but these results are what my server produced. I also realize there can be special conditions where one should consider speed, but seldom is the case where one needs to be concerned about pre-processing a string. The likelihood that it will present a problem is extremely remote. And these results are with today's speeds -- the difference will be less tomorrow and an order of magnitude less in a couple of years, or less.

I guess that what I am trying to say is pick considerations that are significant enough to have real merit. If you can show that your solution can be significantly improved by doing something a certain way, then more power to you. However, simply saying one way is better because it is faster, or uses less memory, doesn't carry the weight it once did. For example, it would have been nice if the net had been based on 8-bit instead of 7-bit, but the people who developed ASCII were concerned about memory. They were right for what they considered important at their time, but those concerns created a larger problem for the industry that followed. The significants of concerns change over time and not realizing that can create problems later.

Cheers,

tedd

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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux