Jump to content

code optimization issue


friedemann_bach

Recommended Posts

Dear Forum,

 

which of the following lines is the more efficient one, regarding parsing time? Or are they all the same?

 

(1) $string = $a.' > '.$b.' > '.$c.' > '.$d;
(2) $string = "$a > $b > $c > $d";

 

I've done some benchmark tests to find out that the second one is only slightly more efficient - can you confirm that?

In which cases would you prefer the first method?

 

Link to comment
https://forums.phpfreaks.com/topic/119451-code-optimization-issue/
Share on other sites

Why is speed an issue with such a code example?

There are loads of methods for constructing a string as above, implode(), sprintf(), printf() are some functions that could do it?

Are you running PHP on a 286 pc?

 

In large scale, high traffic scripts, milliseconds make a huge difference. Nothing wrong with attempting to make a script as efficient as possible.

Ok. Thanks for your proposals. I don't have any experience with Zend and I can't say whether it would help in this issue -- however, I will give it a try. The thing is that my script can produce a different result every time, as it depends a lot on user input. It is an evaluation script that works for a number of different forms. Then, the script is meant to work on environments where developers do not always have the option to install optimizers on their servers on their own.

 

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.