|Don't ask to ask, just ask|
Re: Common Regex Gotchasby Desdinova (Friar)
|on Mar 14, 2001 at 22:41 UTC||Need Help??|
Regarding the simple substitutions section just to prove your point about not going overkill i benchmarked the two ways you mentioned (tr and s) as well as just uc with this code
And got these results:
I know this is not new information but i figured i'd post here to highlight what you are saying.
PS -- The bechmark method stolen from Benchmarking your code
UPDATE: Xxaxx pointed out to me in This Node That I am not making a fair comparision above. The eval of uc($1) in the s/// regex was eating up a lot of the cycles. The gap is smaller than 17:1 shown above...
For a fairer test I compared a single char substituion with tr/// and s///
Using the benchmarking above I got hese results:
Still there is an advantage to tr/// over s/// which can be more noticable depending on your data.
Update 2: petral asked me question in the CB about the way i call uc in method one made me realize that it wont actually do anything because I don't assign the return value back to the var. I updated the code to do that.