Re: [PHP3] Re: [PHP-DEV] Re: [PHP3] PHP Speed Optimization
| From: | Ron Chmara | Date: | Mon, 24 Apr 2000 19:45:31 +0000 |
| Subject: | Re: [PHP3] Re: [PHP-DEV] Re: [PHP3] PHP Speed Optimization | ||
| References: | 1 2 3 4 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-18154@lists.php.net to get a copy of this message | ||
Faisal Nasim wrote:
> | > Try not using functions.
> | > You will get approximately 30+ % more speed.
> This doesn't make much difference.... its an interpreted language,
er... there are differences between PHP3 and PHP4, no? User-defined
functions are often slower in PHP3. The advantage they have is in
*coding*, not parsing. I havn't done the headwork on PHP4 yet, but
in three.. oy. Part of the problem is that PHP users tend to think
less lines of code is faster (not the case, the two are unrelated
in issues of speed), and rather than making the fastest code, they tend
to concentrate on making the _smallest_ code. This is assuming a bycycle
is faster than a Concorde SST, because it's more compact. :-)
> and the only speed loss I can think about is the initialization of
> another pool to store local variables.
Say you have 30 user-built functions in *one* file, 200 lines of code.
Depending on your code base/version, if those are called 10 times per page,
you need to include that code for the parser (file call), and
then as you go through the page, it substitutes out the function code....
plus you've added 20 useless functions of overhead for *every*
parsed page. (Hence, the speed differences between 3 and 4, and the
problem with using functions in 3. They *will* bog your execution
down)
Lots and lots of overhead in that. If you can strip excess functions
out, and speed is your goal, by all means, dump them over the side
as fast as you can, and explicitly code using PHP's internal
functions. Try two or three variants on your code, to see if, for
example, you could get a faster result from a printf or an echo,
a faster loop by only testing (if/case) under a smaller set of
circumstances, and, if you can, avoid *ever* using requires or
includes....
If that's still not fast enough, look into coding directly in
C.
Now, of course, this all makes for faster execution, but your
code can bloat like mad, or become almost unreadable. If the goal,
however, is speed, that is a sacrifice you may *have* to make...
The author of "Real programmers don't use Pascal" once told me
of a four line block of code that he worked on optimizing for
three solid days. When he was done with it, it was 5 pages of
code, and 4000% faster.... ugly as sin, but _fast_.
> I don't know for sure but I wonder if functions are saved in
> the form of special tokens which don't need rechecking
> for syntax once compiled... Zeev?
Well, this would be a PHP4 approach. Some of us are still using
quite a bit of 3 (and still migrating from 2). :-) The rules changed
a bit.
-Bop
--
Brought to you from boop!, the dual boot Linux/Win95 Compaq Presario 1625
laptop, currently running RedHat 6.1. Your bopping may vary.