Related to string finding
Thread -> http://eu.battle.net/wow/en/forum/topic/3429936834
Subscription expired, but was curious to ask for one thing: What is most efficient, for example to use when hooking the chat messages incoming to parse for specific things: Code:
if ("a !teST message"):find("![tT][eE][sS][tT]") then ... end Code:
if ("a !teST message"):lower():find("!test") then ... end |
In your second example, you're adding an extra step (the lower() function), so that's adding overhead. However, the difference between the two is unlikely to even be accurately measurable. Use whichever way you prefer.
|
(I find the :lower one more readable, even the more if the pattern is going to be very long)
Looking forward for someone to do some actual performance tests for us though .. |
I don't have time to run it at the moment, but here's a modified version of a comparison function I used in another thread. If nobody replies with the printed results, I'll run it later tonight.
lua Code:
|
Quote:
Code:
Totals 669.73373221 970.02821804133 Code:
Totals 657.32374345437 983.88305435578 |
It seems it's better to not use :lower() if you can avoid it and rather use pure regex (as simple as that one) but maybe if you have a very long regex it may become slower than using :lower(), not sure, must try adding more matchers (brackets) and see how slower it gets if you double the amount. :D
Still interesting results! |
Still, the speed difference won't be noticable under normal circumstances (eg. using it in a live addon, instead of running it in a loop that repeats 1 million times), so you should just use the one that's easier for you to read.
When you come back to that section of your code after months of not looking at it, the last thing you want to do is spend a lot of time figuring out what a regex pattern does (or is supposed to do). :p |
All times are GMT -6. The time now is 09:34 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI