Re: Script's length, echo, and execution speed

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

 



At 12/23/2006 10:33 AM, Jean-Christophe Roux wrote:
Hello, I have this php script of 3,500 lines with a big switch that is such that on each pass maybe 300 lines of codes are executed at most. The current speed of the file is ok. I like to keep the file like that because at each pass there is a check on the whole script and it fails if there is a typo somewhere. Also, I like to have one file instead of many files. But I am wondering if speed is not severaly hurt. What are the general guidelines in terms of length of script? Also, I am writing things like that: echo '<table>'; echo '<tr>'; echo "<td>Content</td>"; echo '</tr>'; echo '</table>'; I like it this way because the script is visually very well aligned, with one action per line and that makes things easier for me to read and understand. But, so many echoes may be considered bad practice; maybe it impacts speed significantly.


Are you encountering a speed problem or just pondering this theoretically? My guess is that ECHO 'TEXT'; is one of the fastest, most optimized operations the PHP interpreter executes.

But you don't need to guess at it: time it. Check the server logs, or output the current time at the beginning and end of script execution. My guess is that the difference between the execution of your script and one much smaller will lie in a scale of tens or hundreds of milliseconds. Servers are bloody fast; that's their job.

In general I think it's smarter to spend your time making your script easy to read and proofread for you, the human slow link in the development chain, than it is to make it faster to run on a machine. Machines will keep getting faster; you're not likely to.

That said, there are things you can do that make your script more efficient to execute AND to maintain. Personally I favor separating out the HTML into larger, pure chunks that can be proofread more easily than when tags and attributes are atomized and strewn throughout the logic.

Regards,
Paul
--
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