Re: Performance question

From: Date: Fri, 02 Feb 2001 17:07:32 +0000
Subject: Re: Performance question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-37867@lists.php.net to get a copy of this message
"Matthew Mundy" <mmundy1@gl.umbc.edu> wrote: > I was wondering. What kind of performance reduction is there in including > files or using the auto prepended one for a file less than, say, 10 line? > Specifically, I would think that the file IO would be a detriment to such > a small file. Without the includes, code would be repeated, but in PHP, > IMHO, speed is a much more important factor than code size. Anyways, what > would be the performance factors in deciding what goes in an include vs > inline code? I don't think you'll find a noticable difference in speed. To me the benefit of a modular design outweighs the effect on speed. As a rule of thumb, I take any code that will be used in multiple files and store in a separate file, but development speed is my most critical constraint. Reduced file size is a nice side effect, but storage space is so cheap that really doesn't matter. And if you want to increase the speed from the user perspective you may want to look at a combination of caching and sending gzipped data to browsers that support it. There was a tutorial on phpbuilder.com recently about this strategy and with the exception of a few obstacles it works nicely depending on what your output is like. You might want to benchmark including the code inline versus using include() or auto prepending it by writing a program to simulate expected (or heavy) usage of the script in question and using something similar to the code below to track the time that the script took to run. On small simple programs the results will be skewed by the time it takes to actually run the code below, but on longer, more complex scripts that will be neglible when comparing your test cases. <?php // Set start time of script. $time_start = microtime(); $time_start = explode( " ", $time_start ); $time_start = $time_start[1] + $time_start[0]; // Set end time of script. $time_end = microtime(); $time_end = explode( " ", $time_end ); $time_end = $time_end[1] + $time_end[0]; // Measure script run time. $time_run = $time_end - $time_start; // Write output to file. // Left as user exercise. ?> -- Steve Werby COO 24-7 Computer Services, LLC Tel: 804.817.2470 http://www.247computing.com/

« previous php.general (#37867) next »