Text Filter Efficiency in Design Philosophy
|
|
I am creating a Text Filter (which could be used for good, i.e. blocking out curse words, but I am using it for evil).
Regardless, I would like efficient code. Really, my question is how efficient is findtext() ?
Right now, I have a list of words to be found in message and for each word, I search the entire message using findtext(). This means, if I'm looking for six words, findtext() is called six times for every message, which doesn't strike me as very efficient (depending on how well findtext() works).
My other idea is to have the list of words I'm looking for to be sorted alphabetically. Then, when a message is received, it is broken down into individual words and then each word is compared to see if it is in the list. Since the list is sorted, this comparison can be done in O(log(n)). Binary Search Algorithm FTW?
Clearly the second method will require more coding on my part, but findtext() will be removed completely. The question is, is it worth it?
|