Re: [PHP] Structured Code vs. Performance

2007-12-03 Thread Martin Alterisio
2007/12/2, tedd [EMAIL PROTECTED]:

 Oh yes, it's very much like fractals, but the term fractalism is
 usually reserved for art forms based on fractals.

 However, one could conclude that all crystalline forms are a
 real-world examples of fractals. In similar vein, all repetitive
 processes (including programming) could be though of as a fractal
 dependant functions. Interesting food for thought, which also could
 be fractal dependant. :-)


Well, I don't know in your country, but here code is considered, legally
speaking, literature... that means we're actually doing ART

So fractalism is quite appropiate.

Even more, considering that fractal are a mathematical and algorithmical
constructs, it's more pertinent to talk about fractalism in terms of code
writing.


Re: [PHP] Structured Code vs. Performance

2007-12-02 Thread tedd

At 8:56 AM +0100 11/29/07, [EMAIL PROTECTED] wrote:

Looks for me a bit like a philosophical question, but maybe you have
something to say about it nevertheless. A good thing for me would be
something like: up to 125 lines of code you get an adequate performance with
simply parsing it every time, with more than 125 lines you would get a
better performance with using separate files - just kidding, surely the
number of lines in this case is 42 ;-).

Looking forward to your answers
Thomas


Thomas:

I seldom find that performance is adversely affected by good 
structure. So, I strive for good structure.


To me, good structure starts at the function level. Like the lattice 
of a crystal, coding grows and reflects the most basic element. Keep 
that element consistent and you'll find that it will be reflected in 
everything you do.


How's that for philosophical?

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



Re: [PHP] Structured Code vs. Performance

2007-12-02 Thread Martin Alterisio
2007/12/2, tedd [EMAIL PROTECTED]:


 To me, good structure starts at the function level. Like the lattice
 of a crystal, coding grows and reflects the most basic element. Keep
 that element consistent and you'll find that it will be reflected in
 everything you do.

 How's that for philosophical?


I even have a name for your philosophical doctrine: fractalism


Re: [PHP] Structured Code vs. Performance

2007-12-02 Thread tedd

At 8:56 PM -0300 12/2/07, Martin Alterisio wrote:

2007/12/2, tedd mailto:[EMAIL PROTECTED][EMAIL PROTECTED]:


To me, good structure starts at the function level. Like the lattice
of a crystal, coding grows and reflects the most basic element. Keep
that element consistent and you'll find that it will be reflected in
everything you do.

How's that for philosophical?


I even have a name for your philosophical doctrine: fractalism


Oh yes, it's very much like fractals, but the term fractalism is 
usually reserved for art forms based on fractals.


However, one could conclude that all crystalline forms are a 
real-world examples of fractals. In similar vein, all repetitive 
processes (including programming) could be though of as a fractal 
dependant functions. Interesting food for thought, which also could 
be fractal dependant. :-)


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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Robert Cummings
On Thu, 2007-11-29 at 08:56 +0100, [EMAIL PROTECTED] wrote:
 I got different portions of code only used for certain purposes (who don't 
 ;-)?). But what, in your opinion (better: in your experience) would be the 
 best regarding script-performance: Putting each code-portion in a separate 
 file and include it if required, putting it in a constant-dependent 
 if-structure (if (defined('FOO')  FOO) {class foo{}; function foo(); ...}) 
 or simply let it be parsed every time?
 
 My first choice is using separate files, but if a file e.g. only contains 20 
 lines, I fear it would take much longer to include the file against simply 
 parsing these lines in the existing file. And as parsing is done really 
 fast, there might be no real performance-loss in case of not using the 
 mentioned code. With the constant-dependent if-structure I don't know if 
 there are any performance-benefits if FOO isn't defined or defined as FALSE.
 
 Looks for me a bit like a philosophical question, but maybe you have 
 something to say about it nevertheless. A good thing for me would be 
 something like: up to 125 lines of code you get an adequate performance with 
 simply parsing it every time, with more than 125 lines you would get a 
 better performance with using separate files - just kidding, surely the 
 number of lines in this case is 42 ;-).

Install a compile cache like eaccelerator or APC. keep your code
organized, that usually means use multiple files for the code.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



RE: [PHP] Structured Code vs. Performance

2007-11-29 Thread Tomi Kaistila
 I got different portions of code only used for certain purposes (who
 don't
 ;-)?). But what, in your opinion (better: in your experience) would be
 the
 best regarding script-performance: Putting each code-portion in a
 separate
 file and include it if required, putting it in a constant-dependent
 if-structure (if (defined('FOO')  FOO) {class foo{}; function foo();
 ...})
 or simply let it be parsed every time?
 
 My first choice is using separate files, but if a file e.g. only
 contains 20
 lines, I fear it would take much longer to include the file against
 simply
 parsing these lines in the existing file. And as parsing is done really
 fast, there might be no real performance-loss in case of not using the
 mentioned code. With the constant-dependent if-structure I don't know
 if
 there are any performance-benefits if FOO isn't defined or defined as
 FALSE.
 
 Looks for me a bit like a philosophical question, but maybe you have
 something to say about it nevertheless. A good thing for me would be
 something like: up to 125 lines of code you get an adequate performance
 with
 simply parsing it every time, with more than 125 lines you would get a
 better performance with using separate files - just kidding, surely the
 number of lines in this case is 42 ;-).
 
 Looking forward to your answers
 Thomas

To my understanding (and anyone who thinks differently can correct me) there
is very little performance loss in including (or requiring) multiple files,
unless the number of files reaches something like over a hundred. This says
nothing about the amount of code in those file of course. But like you said,
parsing is fast.

I personally prefer the approuch:

1 directory = package
1 subdirectory = subpackage
1 .php file = class

I haven't noticed that much performance degradation in my scripts, while
have amounts several dozen of files.

You can avoid duplication by only using require_once or include_once. PHP
automatically does the checking that the file is not included if it has
already been included once. The Zend framework works this way for instance.
Just simply require_once, at the beginning of the file, everything the file
in question needs.

Constants on the global scope are a bit of a different case. But if you do a
lot of objects, you can instead of the global scope put all of your
constants into classes, which works just as well. This avoids name
conflicts.

Hope that answered your question.


Tomi Kaistila
PHP Developer

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Chris

[EMAIL PROTECTED] wrote:
I got different portions of code only used for certain purposes (who don't 
;-)?). But what, in your opinion (better: in your experience) would be the 
best regarding script-performance: Putting each code-portion in a separate 
file and include it if required, putting it in a constant-dependent 
if-structure (if (defined('FOO')  FOO) {class foo{}; function foo(); ...}) 
or simply let it be parsed every time?


Make your code readable and manageable first, then worry about the rest. 
I always go for multiple files because it means the project is much more 
manageable.


My first choice is using separate files, but if a file e.g. only contains 20 
lines, I fear it would take much longer to include the file against simply 
parsing these lines in the existing file.


Put your misc functions in one file and include it when you need it.

--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Jochem Maas
[EMAIL PROTECTED] wrote:
 I got different portions of code only used for certain purposes (who don't 
 ;-)?). But what, in your opinion (better: in your experience) would be the 
 best regarding script-performance: Putting each code-portion in a separate 
 file and include it if required, putting it in a constant-dependent 
 if-structure (if (defined('FOO')  FOO) {class foo{}; function foo(); ...}) 

defining functions or classes conditionally is not recommended, because it
means they can only be defined at runtime and not compile time ... which will
kill any op-code caching you might have in place or use in future (e.g. 
php.net/apc)

 or simply let it be parsed every time?
 
 My first choice is using separate files, but if a file e.g. only contains 20 
 lines, I fear it would take much longer to include the file against simply 
 parsing these lines in the existing file. And as parsing is done really 
 fast, there might be no real performance-loss in case of not using the 
 mentioned code. With the constant-dependent if-structure I don't know if 
 there are any performance-benefits if FOO isn't defined or defined as FALSE.
 
 Looks for me a bit like a philosophical question, but maybe you have 
 something to say about it nevertheless. A good thing for me would be 
 something like: up to 125 lines of code you get an adequate performance with 
 simply parsing it every time, with more than 125 lines you would get a 
 better performance with using separate files - just kidding, surely the 
 number of lines in this case is 42 ;-).

for a few 1000 lines of code the difference is probably not measurable in any
meaningful way (a spam assassin deamon, or something similar, hogging the CPU
will probably have more realworld effect on the speed of your script).

when your app becomes very large you will probably benefit from only including
little used code when it is actually required.

there is also the issue of maintainability - having to check and keep track of
include/require statements scattered all through the code, and working through
'undefined class/function' errors when enhancing/bugfixing/refactoring code 
maybe
alot more hassle than using a single global 'init' script that includes pretty 
much
everything bit of code your scripts might need.

personally I tend to go for maintainability over performance if the choice is
mutually exclusive - generally your time is alot more costly than the purchase
and placement of extra RAM, faster CPU, faster disks, etc.

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Jochem Maas
Tomi Kaistila wrote:

...

 
 You can avoid duplication by only using require_once or include_once. PHP

indeed require_once() and include_once() help with maintainability but it
should be mentioned that if you are going to use an op-code cache (as Rob
Cummings mentioned also) then it is highly recommended that you stick to
using require() and include() as, IIRC, op-code caches handle your includes
much faster when they are 'unconditional' (probably not the correct word in this
context but what I mean is that there is no check to see if the file has been
previously included)

also using an absolute path in your include statements helps php (and the
op-code cache if you use it) it go a little faster because there is no need
to work through the directories defined in the include_path ini setting to
find the file.

 automatically does the checking that the file is not included if it has
 already been included once. The Zend framework works this way for instance.
 Just simply require_once, at the beginning of the file, everything the file
 in question needs.
 
 Constants on the global scope are a bit of a different case. But if you do a
 lot of objects, you can instead of the global scope put all of your
 constants into classes, which works just as well. This avoids name
 conflicts.
 
 Hope that answered your question.
 
 
 Tomi Kaistila
 PHP Developer
 

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Stut

Jochem Maas wrote:

[EMAIL PROTECTED] wrote:
I got different portions of code only used for certain purposes (who don't 
;-)?). But what, in your opinion (better: in your experience) would be the 
best regarding script-performance: Putting each code-portion in a separate 
file and include it if required, putting it in a constant-dependent 
if-structure (if (defined('FOO')  FOO) {class foo{}; function foo(); ...}) 


defining functions or classes conditionally is not recommended, because it
means they can only be defined at runtime and not compile time ... which will
kill any op-code caching you might have in place or use in future (e.g. 
php.net/apc)


I'm not completely sure, but I think you're wrong there. Removing the 
condition in the example above will not affect any opcode caching since 
PHP cannot determine the result of that conditional until runtime.


To the OP: You're treading on the dangerous ground of premature 
optimisation. In the grand scheme of things the time taken for PHP to 
compile your scripts is tiny compared to the time it will take to run 
it. And as mentioned there are several ways to cache the compilation 
output which turns that tiny time into a negligible time.


Worry about the structure and maintainability of your app rather than 
thinking about how fast it is. Once you have the app doing something 
useful you can start to think about how to make it do it quickly.


-Stut

--
http://stut.net/

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Jochem Maas
Stut wrote:
 Jochem Maas wrote:
 [EMAIL PROTECTED] wrote:
 I got different portions of code only used for certain purposes (who
 don't ;-)?). But what, in your opinion (better: in your experience)
 would be the best regarding script-performance: Putting each
 code-portion in a separate file and include it if required, putting
 it in a constant-dependent if-structure (if (defined('FOO')  FOO)
 {class foo{}; function foo(); ...}) 

 defining functions or classes conditionally is not recommended,
 because it
 means they can only be defined at runtime and not compile time ...
 which will
 kill any op-code caching you might have in place or use in future
 (e.g. php.net/apc)
 
 I'm not completely sure, but I think you're wrong there. Removing the
 condition in the example above will not affect any opcode caching since
 PHP cannot determine the result of that conditional until runtime.

one of us is reading the other's post incorrectly - I have a feeling we are
both trying to say the same thing.

namely runtime class definitions don't have the same benefit of op-code caching
as compiletime definitions.

or not?

 
 To the OP: You're treading on the dangerous ground of premature
 optimisation. In the grand scheme of things the time taken for PHP to
 compile your scripts is tiny compared to the time it will take to run
 it. And as mentioned there are several ways to cache the compilation
 output which turns that tiny time into a negligible time.
 
 Worry about the structure and maintainability of your app rather than
 thinking about how fast it is. Once you have the app doing something
 useful you can start to think about how to make it do it quickly.
 
 -Stut
 


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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Stut

Jo chem baas wrote:

Stut wrote:

Jochem Maas wrote:

[EMAIL PROTECTED] wrote:

I got different portions of code only used for certain purposes (who
don't ;-)?). But what, in your opinion (better: in your experience)
would be the best regarding script-performance: Putting each
code-portion in a separate file and include it if required, putting
it in a constant-dependent if-structure (if (defined('FOO')  FOO)
{class foo{}; function foo(); ...}) 

defining functions or classes conditionally is not recommended,
because it
means they can only be defined at runtime and not compile time ...
which will
kill any op-code caching you might have in place or use in future
(e.g. php.net/apc)

I'm not completely sure, but I think you're wrong there. Removing the
condition in the example above will not affect any opcode caching since
PHP cannot determine the result of that conditional until runtime.


one of us is reading the other's post incorrectly - I have a feeling we are
both trying to say the same thing.

namely runtime class definitions don't have the same benefit of op-code caching
as compiletime definitions.

or not?


Not ;). There is no such thing as a compile-time definition in PHP.

Whether there is conditional definition or not, the opcode cache will 
look the same. The reason for this is that function and class 
definitions happen at runtime not compile time. This would have to be 
the case for conditional definition to work at all, since the compiler 
cannot determine the value of a condition at compile-time.


-Stut

--
http://stut.net/

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Jochem Maas
Stut wrote:
 Jo chem baas wrote:
 Stut wrote:
 Jochem Maas wrote:
 [EMAIL PROTECTED] wrote:
 I got different portions of code only used for certain purposes (who
 don't ;-)?). But what, in your opinion (better: in your experience)
 would be the best regarding script-performance: Putting each
 code-portion in a separate file and include it if required, putting
 it in a constant-dependent if-structure (if (defined('FOO')  FOO)
 {class foo{}; function foo(); ...}) 
 defining functions or classes conditionally is not recommended,
 because it
 means they can only be defined at runtime and not compile time ...
 which will
 kill any op-code caching you might have in place or use in future
 (e.g. php.net/apc)
 I'm not completely sure, but I think you're wrong there. Removing the
 condition in the example above will not affect any opcode caching since
 PHP cannot determine the result of that conditional until runtime.

 one of us is reading the other's post incorrectly - I have a feeling
 we are
 both trying to say the same thing.

 namely runtime class definitions don't have the same benefit of
 op-code caching
 as compiletime definitions.

 or not?
 
 Not ;). There is no such thing as a compile-time definition in PHP.
 
 Whether there is conditional definition or not, the opcode cache will
 look the same. The reason for this is that function and class
 definitions happen at runtime not compile time. This would have to be
 the case for conditional definition to work at all, since the compiler
 cannot determine the value of a condition at compile-time.

okay, but I was just paraphrasing the man Rasmus, although I admit I may
have misinterpreted (or misundersstood the 'why') - thought I pretty sure
he has written on a number of occasions that code like the following sucks
for op-code caches and should be avoided:

if (foo()) {
class Foo { }
}

 
 -Stut
 

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Stut

Jochem Maas wrote:

Stut wrote:

Jo chem baas wrote:

Stut wrote:

Jochem Maas wrote:

[EMAIL PROTECTED] wrote:

I got different portions of code only used for certain purposes (who
don't ;-)?). But what, in your opinion (better: in your experience)
would be the best regarding script-performance: Putting each
code-portion in a separate file and include it if required, putting
it in a constant-dependent if-structure (if (defined('FOO')  FOO)
{class foo{}; function foo(); ...}) 

defining functions or classes conditionally is not recommended,
because it
means they can only be defined at runtime and not compile time ...
which will
kill any op-code caching you might have in place or use in future
(e.g. php.net/apc)

I'm not completely sure, but I think you're wrong there. Removing the
condition in the example above will not affect any opcode caching since
PHP cannot determine the result of that conditional until runtime.

one of us is reading the other's post incorrectly - I have a feeling
we are
both trying to say the same thing.

namely runtime class definitions don't have the same benefit of
op-code caching
as compiletime definitions.

or not?

Not ;). There is no such thing as a compile-time definition in PHP.

Whether there is conditional definition or not, the opcode cache will
look the same. The reason for this is that function and class
definitions happen at runtime not compile time. This would have to be
the case for conditional definition to work at all, since the compiler
cannot determine the value of a condition at compile-time.


okay, but I was just paraphrasing the man Rasmus, although I admit I may
have misinterpreted (or misundersstood the 'why') - thought I pretty sure
he has written on a number of occasions that code like the following sucks
for op-code caches and should be avoided:

if (foo()) {
class Foo { }
}


Hopefully he's reading and will be able to give us a definitive answer.

I'm going by my experience of stepping through code with Zend Studio, 
but it's possible (probably likely) that ZE does something slightly 
different when a debugger is attached.


-Stut

--
http://stut.net/

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Paul Scott

On Thu, 2007-11-29 at 13:51 +0100, Jochem Maas wrote:
 okay, but I was just paraphrasing the man Rasmus, although I admit I
 may
 have misinterpreted (or misundersstood the 'why') - thought I pretty
 sure
 he has written on a number of occasions that code like the following
 sucks
 for op-code caches and should be avoided:
 
 if (foo()) {
   class Foo { }
 }
 

As I have always understood it, the heavyness only really comes in when
there are conditional includes or requires

if (foo()) {
require_once('foo_class_inc.php');
}
else {
// ...
}

--Paul

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm 

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

Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Jochem Maas
Stut wrote:
 Jochem Maas wrote:
 Stut wrote:
 Jo chem baas wrote:

^- wtf happened here? :-) it's quite funny if you know dutch :-)

...

 Whether there is conditional definition or not, the opcode cache will
 look the same. The reason for this is that function and class
 definitions happen at runtime not compile time. This would have to be
 the case for conditional definition to work at all, since the compiler
 cannot determine the value of a condition at compile-time.

 okay, but I was just paraphrasing the man Rasmus, although I admit I may
 have misinterpreted (or misundersstood the 'why') - thought I pretty sure
 he has written on a number of occasions that code like the following
 sucks
 for op-code caches and should be avoided:

 if (foo()) {
 class Foo { }
 }
 
 Hopefully he's reading and will be able to give us a definitive answer.

here is the post that I was recalling:

http://lists.nyphp.org/pipermail/talk/2006-March/017676.html

I believe his third point validates what I was saying although I did
make a bit of a mess with regard of my use of terminology.

 
 I'm going by my experience of stepping through code with Zend Studio,
 but it's possible (probably likely) that ZE does something slightly
 different when a debugger is attached.
 
 -Stut
 

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Jochem Maas
[EMAIL PROTECTED] wrote:
 Just to be curious:
 
 when something like
 
 if (defined('FOO')  FOO) {
   class foo{};
   function foo(){};
 }
 
 is parsed and FOO is not defined, will the code inside be parsed 
 nevertheless? Or is anything inside skipped, leading to a (fragments of 
 microseconds) faster handling of the code? Thus to go to my original 
 question concerning speed: Would I save time with this construct as I would 
 save it with skipping an include()?

no. regardless of whether that is actually true, still no.
it's crufty.

they have a word very suitable to this situation in dutch 'mierenneuken',
personally I'd stick with pretty girls.

 
 Thomas 
 

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Stut

Jochem Maas wrote:

Stut wrote:

Jochem Maas wrote:

Stut wrote:

Jo chem baas wrote:


^- wtf happened here? :-) it's quite funny if you know dutch :-)


Pass. Looking back it looks like it happened one of the times I replied. 
Didn't do it on purpose, honest! ;)



Whether there is conditional definition or not, the opcode cache will
look the same. The reason for this is that function and class
definitions happen at runtime not compile time. This would have to be
the case for conditional definition to work at all, since the compiler
cannot determine the value of a condition at compile-time.

okay, but I was just paraphrasing the man Rasmus, although I admit I may
have misinterpreted (or misundersstood the 'why') - thought I pretty sure
he has written on a number of occasions that code like the following
sucks
for op-code caches and should be avoided:

if (foo()) {
class Foo { }
}

Hopefully he's reading and will be able to give us a definitive answer.


here is the post that I was recalling:

http://lists.nyphp.org/pipermail/talk/2006-March/017676.html

I believe his third point validates what I was saying although I did
make a bit of a mess with regard of my use of terminology.


Hmm, Rasmus seems to be saying that opcode caches have a way to optimise 
the definition of entities, and by defining them conditionally they 
can't make use of that. That kinda makes sense, but I'd expect the 
difference to be negligible unless you're talking about a file with 
thousands upon thousands of definitions.


Anyhoo, back to the coalface.

-Stut

--
http://stut.net/

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread news_yodpeirs
Just to be curious:

when something like

if (defined('FOO')  FOO) {
  class foo{};
  function foo(){};
}

is parsed and FOO is not defined, will the code inside be parsed 
nevertheless? Or is anything inside skipped, leading to a (fragments of 
microseconds) faster handling of the code? Thus to go to my original 
question concerning speed: Would I save time with this construct as I would 
save it with skipping an include()?

Thomas 

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread news_yodpeirs
 they have a word very suitable to this situation in dutch 'mierenneuken',
 personally I'd stick with pretty girls.

OT: Couldn't translate that in german, the nearest approach seems to be 
Haarspalterei but unfortunately for me this seems not to match the 
situation. And it doesn't meet pretty girls too :-D.

But so in fact conditional definitions are absolutely useless - apart from 
giving the parser some work without using it's outcome?

Thomas 



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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread T . Lensselink
On Thu, 29 Nov 2007 14:54:43 +0100, Jochem Maas [EMAIL PROTECTED]
wrote:
 [EMAIL PROTECTED] wrote:
 Just to be curious:

 when something like

 if (defined('FOO')  FOO) {
   class foo{};
   function foo(){};
 }

 is parsed and FOO is not defined, will the code inside be parsed
 nevertheless? Or is anything inside skipped, leading to a (fragments of
 microseconds) faster handling of the code? Thus to go to my original
 question concerning speed: Would I save time with this construct as I
 would
 save it with skipping an include()?
 
 no. regardless of whether that is actually true, still no.
 it's crufty.
 
 they have a word very suitable to this situation in dutch 'mierenneuken',
 personally I'd stick with pretty girls.

mierenneuker :)

Pretty girls over crufty code any day of the week!

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Larry Garfield
On Thursday 29 November 2007, Jochem Maas wrote:

 okay, but I was just paraphrasing the man Rasmus, although I admit I may
 have misinterpreted (or misundersstood the 'why') - thought I pretty sure
 he has written on a number of occasions that code like the following sucks
 for op-code caches and should be avoided:

 if (foo()) {
   class Foo { }
 }

That's bad because the compiler will *still* parse and compile class Foo(), 
but give it some ridiculous internal name so that it's inaccessible.  It will 
then, at runtime, conditionally give it a real name so that it then becomes 
accessible.  You'll still have the same cost to parse and compile class Foo() 
either way.  There is no savings in either compile time or memory use.

if (foo()) {
   include('foo.php');
}

This will make baby opcode cache cry, from what I understand, but will not 
balloon the memory usage the way the former code will.  In practice, though, 
a modular, pluggable system (most of what I use) is going to end up having 
conditional includes no matter what you do so I generally don't pay much 
attention to that type of optimization, since it's irrelevant to me anyway.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
Jefferson

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Robert Cummings
On Thu, 2007-11-29 at 12:13 +, Stut wrote:

 Not ;). There is no such thing as a compile-time definition in PHP.

There certainly is...

?php

if( !function_exists( 'file_put_contents' ) )
{
$def = _
   
function file_put_contents
( \$filename, \$data, \$flags=0, \$context=null )
{
// :)
}
_;
  
eval( $def );

}

?

Now, I'm not necessarily advocating this style of compatibility
programming, but I remember seeing something like it in PEAR. I think it
might have been the pear SOAP classes where the classes had to be
declared dynamically.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Robert Cummings
On Thu, 2007-11-29 at 16:49 +, Stut wrote:
 Robert Cummings wrote:
  On Thu, 2007-11-29 at 12:13 +, Stut wrote:
  Not ;). There is no such thing as a compile-time definition in PHP.
  
  There certainly is...
  
  ?php
  
  if( !function_exists( 'file_put_contents' ) )
  {
  $def = _
 
  function file_put_contents
  ( \$filename, \$data, \$flags=0, \$context=null )
  {
  // :)
  }
  _;

  eval( $def );
  
  }
  
  ?
  
  Now, I'm not necessarily advocating this style of compatibility
  programming, but I remember seeing something like it in PEAR. I think it
  might have been the pear SOAP classes where the classes had to be
  declared dynamically.
 
 That's a runtime definition. It has to be. The function_exists function 
 *cannot* be run at compile-time to see what the result is, so it must 
 happen at runtime.

Bleh, just read your comments and then read the comment I quoted and I
find myself needing a morning wakeup slap :) Your comment at the top
says compile-time, not run-time. I'm going to go find a big rock *hehe*.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



Re: [PHP] Structured Code vs. Performance

2007-11-29 Thread Stut

Robert Cummings wrote:

On Thu, 2007-11-29 at 12:13 +, Stut wrote:

Not ;). There is no such thing as a compile-time definition in PHP.


There certainly is...

?php

if( !function_exists( 'file_put_contents' ) )
{
$def = _
   
function file_put_contents

( \$filename, \$data, \$flags=0, \$context=null )
{
// :)
}
_;
  
eval( $def );


}

?

Now, I'm not necessarily advocating this style of compatibility
programming, but I remember seeing something like it in PEAR. I think it
might have been the pear SOAP classes where the classes had to be
declared dynamically.


That's a runtime definition. It has to be. The function_exists function 
*cannot* be run at compile-time to see what the result is, so it must 
happen at runtime.


I think maybe the confusion is over terminology. In my mind Zend Studio 
would not let me step through a compile-time process, but it's looking 
likely that that's precisely what it's doing if I'm to believe 
everything I'm reading.


Here's what I see when a file is included... I can step through each 
function definition line (function ...), and at the same time it 
executes any inline code outside of the functions. That seems like a 
runtime process to me. If there is a function definition contained 
within the file, or a function defined within a function, the debugger 
does not hit that definition unless the condition matches or the 
function is called.


To me this indicates that PHP defines entities at run time. It's 
possible that it also defines them at compile-time, but I don't know the 
internals well enough to know.


-Stut

--
http://stut.net/

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