Performance Comparison Between Ucwords and Ucfirst
We all know for sure Ucwords is heavier than Ucfirst but before you guys all comment why the hell you compare these function, i’ll tell you the reason. My colleague and I are working on SEO tasks today and came across some text that the first letter need to be capitalized. In PHP, these two function can be used to serve that purpose, and then
because we are both under stressed circumstances, the deadline is freaking tomorrow, suddenly the thought of comparing these 2 functions crossed my mind. “Lets compare ucwords and ucfirst performance if the input word is 1.” LOL.
For you guys that super curious how we do it and the result, here is the code.
In this code above, we capitalize one word “pelanggaran” as the input. We loop this process using 2 different function 1 million times, and we count how long it takes to do the process.
Here are the results… (as we expected)
ucfirst: 55.7820796967 seconds
So the conclusion is DON’T USE UCWORDS TO CAPITALIZED FIRST LETTER OF 1 WORD. Two times longer that Ucfirst.
Although this experiment was useless, but the fun time and laughs that counts. LOL.
Thanks @dimasdanz that make time to write the codes.