Re: [PHP] optimal code

2001-07-05 Thread Thies C. Arntzen

On Thu, Jul 05, 2001 at 02:29:12PM +0300, Adrian Ciutureanu wrote:
 Is any of the versions below more effective?
 
 /** Version 1 **/
 ?
 if($condition) {
 // some big code
 } else {
 // other big code
 }
 ?
 
 /** Version 2 **/
 ?
 if($condition) {
 include 'file_with_some _big_code.php';
 } else {
 include 'file_with_other_big_code.php';
 }
 ?
 
 /** Version 3 **/
 ?
 if($condition) {
 require 'file_with_some _big_code.php';
 } else {
 require 'file_with_other_big_code.php';
 }
 ?

i'd bet no #2. but to be sure benchmark it.

tc

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] optimal code

2001-07-05 Thread Justin Farnsworth

This depends upon what you mean by effective.  For administration
purposes, it may be that you want to include some commen code,
and therefore not rewrite reusable bits.

If you are talking about speed, opening a file is expensive
because it is a kernel call, a directory search and all that.
Your some big code in-line will beat it every time...

If you require, and the thingy has been already loaded, then
you will have to analyze how many times you use it, and
try to determine tradeoffs.  This is difficult.

My take is, unless you are getting 100,000 hits a day and
your server load is 0.99, do what is best for reusability,
clarity, and administration purposes.

_jef

--
Adrian Ciutureanu wrote:
 
 Is any of the versions below more effective?
 
 /** Version 1 **/
 ?
 if($condition) {
 // some big code
 } else {
 // other big code
 }
 ?
 
 /** Version 2 **/
 ?
 if($condition) {
 include 'file_with_some _big_code.php';
 } else {
 include 'file_with_other_big_code.php';
 }
 ?
 
 /** Version 3 **/
 ?
 if($condition) {
 require 'file_with_some _big_code.php';
 } else {
 require 'file_with_other_big_code.php';
 }
 ?
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
Justin Farnsworth
Eye Integrated Communications
321 South Evans - Suite 203
Greenville, NC 27858 | Tel: (252) 353-0722

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] optimal code

2001-07-05 Thread Richard Heyes

 If you are talking about speed, opening a file is expensive
 because it is a kernel call, a directory search and all that.
 Your some big code in-line will beat it every time...

Not in my experience. I have a file which defines ~40 functions, with
the bodies
included when the function is called. Eg:

function blah(){

return include('includes/func.blah.inc');
}

Having all the function bodies in the same file would cause php to have
to parse all
of that code, probably about 3-4000 lines causing awful slowdowns. And
the reason to define all of
the functions in one file, is so that we can include that file, and all
the functions are then available.

-- 
Richard Heyes

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] optimal code

2001-07-05 Thread Nick Davies



surely the include function only pastes the contents of the included
file into the point where the include statement occours. Php still has to
parse it all.

On Thu, 5 Jul 2001, Richard Heyes wrote:

  If you are talking about speed, opening a file is expensive
  because it is a kernel call, a directory search and all that.
  Your some big code in-line will beat it every time...
 
 Not in my experience. I have a file which defines ~40 functions, with
 the bodies
 included when the function is called. Eg:
 
 function blah(){
 
   return include('includes/func.blah.inc');
 }
 
 Having all the function bodies in the same file would cause php to have
 to parse all
 of that code, probably about 3-4000 lines causing awful slowdowns. And
 the reason to define all of
 the functions in one file, is so that we can include that file, and all
 the functions are then available.
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] optimal code

2001-07-05 Thread Justin Farnsworth

But, my friend, if you include that file, PHP _still_ has
to parse it.  You just didn't benchmark.  No matter what

?php
big_code_inline;
(which PHP has to interpret)
?

will beat

?php
include file_with_big_code_inline
(which PHP has to interpret)
?

because of the addition of the call to the kernel.  You
cannot get around this.


Richard Heyes wrote:
 
  If you are talking about speed, opening a file is expensive
  because it is a kernel call, a directory search and all that.
  Your some big code in-line will beat it every time...
 
 Not in my experience. I have a file which defines ~40 functions, with
 the bodies
 included when the function is called. Eg:
 
 function blah(){
 
 return include('includes/func.blah.inc');
 }
 
 Having all the function bodies in the same file would cause php to have
 to parse all
 of that code, probably about 3-4000 lines causing awful slowdowns. And
 the reason to define all of
 the functions in one file, is so that we can include that file, and all
 the functions are then available.
 
 --
 Richard Heyes

-- 
Justin Farnsworth
Eye Integrated Communications
321 South Evans - Suite 203
Greenville, NC 27858 | Tel: (252) 353-0722

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] optimal code

2001-07-05 Thread Justin Farnsworth

Nick Davies wrote:
 
 surely the include function only pastes the contents of the included
 file into the point where the include statement occours. Php still has to
 parse it all.
---

Right, and so no matter what, you still have the extra cost
of the file operation, something almost a magnitude slower that
PHP running through it...

--
 On Thu, 5 Jul 2001, Richard Heyes wrote:
 
   If you are talking about speed, opening a file is expensive
   because it is a kernel call, a directory search and all that.
   Your some big code in-line will beat it every time...
 
  Not in my experience. I have a file which defines ~40 functions, with
  the bodies
  included when the function is called. Eg:
 
  function blah(){
 
return include('includes/func.blah.inc');
  }
 
  Having all the function bodies in the same file would cause php to have
  to parse all
  of that code, probably about 3-4000 lines causing awful slowdowns. And
  the reason to define all of
  the functions in one file, is so that we can include that file, and all
  the functions are then available.
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
Justin Farnsworth
Eye Integrated Communications
321 South Evans - Suite 203
Greenville, NC 27858 | Tel: (252) 353-0722

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] optimal code

2001-07-05 Thread Richard Heyes

 But, my friend, if you include that file, PHP _still_ has
 to parse it.  You just didn't benchmark.  No matter what

Actually, I did do benchmarks, you simply didn't understand correctly.
Not all of the functions are used on every page. So if I were to include
all the functions in one file, roughly 30 functions worth of code would
need to be unnecessarily parsed, which obviously causes unecessary
slowdown. This is similar to the original version 2:

/** Version 2 **/
?
if($condition) {
include 'file_with_some _big_code.php';
} else {
include 'file_with_other_big_code.php';
}
?

This code will run one set of code. Having the other set of big_code
parsed is pointless. FWIW, it's this cutting out of parsing code that
makes the Zend Cache produce such high speed increases.
-- 
Richard Heyes

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] optimal code

2001-07-05 Thread teo

Hi Richard!
On Thu, 05 Jul 2001, Richard Heyes wrote:

  If you are talking about speed, opening a file is expensive
  because it is a kernel call, a directory search and all that.
  Your some big code in-line will beat it every time...
 
 Not in my experience. I have a file which defines ~40 functions, with
 the bodies
 included when the function is called. Eg:
 
 function blah(){
 
   return include('includes/func.blah.inc');
 }
 
 Having all the function bodies in the same file would cause php to have
 to parse all
 of that code, probably about 3-4000 lines causing awful slowdowns. And
 the reason to define all of
 the functions in one file, is so that we can include that file, and all
 the functions are then available.
hmm, depending on the function size I would say the parser is much faster
doing that than the HDD drive reading each file from the disk and ending
in lesser php code to parse.

OTOH, it is not possible to do your way w/ class methods :((

I guess the ammoun of include/one-shot-code depends on the application,
programming style, but somewhere they should balance.


-- teodor

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] optimal code

2001-07-05 Thread Richard Heyes

  Having all the function bodies in the same file would cause php to have
  to parse all
  of that code, probably about 3-4000 lines causing awful slowdowns. And
  the reason to define all of
  the functions in one file, is so that we can include that file, and all
  the functions are then available.

 hmm, depending on the function size I would say the parser is much faster
 doing that than the HDD drive reading each file from the disk and ending
 in lesser php code to parse.

Indeed. One thing I forgot to mention, is that IIRC most OS's will cache
commnly used files, so if you use this method on a busy site, it may make
fewer calls to disk than anticipated.
As always, YMMV, and benchmarking will show the true path to follow. If you
really want to improve performance, mainly on time consuming or DB intensive
scripts, you may be interested in the output cache app on my website.

 OTOH, it is not possible to do your way w/ class methods :((

Sure is, though admittedly it's not as nice:

class my_class{

var $a;
var $b;

function my_class(){
return include('functions/class.my_class.func.my_class.inc');
}

function my_func(){
return include('functions/class.my_class.func.my_func.inc');
}
}

 I guess the ammoun of include/one-shot-code depends on the application,
 programming style, but somewhere they should balance.

For sure.

--
Richard Heyes
http://www.heyes-computing.net
Everything should be made as simple as possible, but not simpler. - Albert
Einstein


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]