Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.
Popular code excerpts may be moved to "Code Snippets" by the moderators.
$string = 'The Colts will make the playoffs, but the ...Jaguars continued to open the wound that is
their rush defense. Vic Carucci wonders how far Indy can go in his snapshots.';
echo lcwords(strtoupper($string));
tHE cOLTS wILL mAKE tHE pLAYOFFS, bUT tHE ...jAGUARS cONTINUED tO oPEN tHE wOUND tHAT iS tHEIR rUSH dEFENSE. vIC cARUCCI wONDERS hOW fAR iNDY cAN gO iN hIS sNAPSHOTS.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Are you aware that in this manner you practically lose the said 28% performance boost? Plus the yet unmeasured additional boost of pre-compiled code, which create_function() can't use.
Come on! "Littering the namespace" is worse than fast(er) code?
I'm surprised you feel so strongly. Its really a matter context. Which is more important: namespace preservation or performance?
I just happened to choose namespace preservation because all I'm doing at the moment, in terms of code, is writing a library. A good library doesn't litter the namespace.
Whilst I choose namespace preservation over performance I didn't neglate performance entirely by using a static that circumvents most of the performance loss by using create_function. I only did that because it was easy to do and I knew it would work. Having said all that with a class there isn't a problem:
ole wrote:Having said all that with a class there isn't a problem
Ah, this is indeed a perfect solution for the objections of both of us!
ole wrote:How much faster?
28%
If you test it with a loop indeed the function will be created only once, which is perfect. BUT, If you have a script that calls this just a couple of times, but is hit many times by different users, that busyness with the "static" function will not be of much use, hence you'll have the same performance loss as when not using static. What I was so passionately against is making wrong decisions based on incorrectly made tests.
Contextual again...If the lcwords using the static is only being executed once and you are having performance issues from it (in my opinion this is an unlikely scenario but I'll play along anyway) then yes using an external function is a good idea, if its being executed more than once then..