Jump to content

[SOLVED] Which is more efficient?


DSGameMaker

Recommended Posts

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 ;)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.