Jump to content

[SOLVED] Which is more efficient?


DSGameMaker

Recommended Posts

inside a loop that ran 1,000,000 times, running on my mid-range pc, the difference was about 0.2 seconds with ($name == "") being that faster one.

 

aka...not a real difference. on a similar note...(empty($name)) was faster by a hair

Wow, didn't expect this much discussion.

 

I'm going to continue using

 

(strlen($name) == 0)

 

I seem to beleive that working with a string uses more memory than a number, and that PHP has to free up a chunk to hold what could be 200 different ASCII characters, when actually, the string is empty. I bet I am wrong, but I don't know.

 

It's good to see the difference is only minimal though ;)

When you work with a string literal like that in a boolean statement, it won't actually allocate more than the length that you actually provide.  When you say "", it doesn't actually allocate any new space other than whatever data it has to give to the yylval in Flex and Bison.  The thing is, you should use trim() regardless.  Then you'd have:

strlen(trim($name))

 

And two function calls are much heavier than 1.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.