Re: Fast way to determine if a string contains a member of a list of strings
- From: "Karch" <news.microsoft.com>
- Date: Wed, 12 Mar 2008 22:54:49 -0500
WOW! Really disappointing timings for the state machine method. Here are the
results:
Method: Looping through 359 strings doing an if (IndexOf > 0) and a source
string of length = 47
Execution time: 0.055008 seconds.
Method: Using the StateMachine method on 359 strings and a source string of
length = 47
Execution time: 2.359223 seconds.
In my case, I can terminate the search as soon as ONE of the strings is
found because the list is mutually exclusive. In the sample code that you
provided, at what point do I know I have a match and can terminate the
traversal?
Also, to answer your question, I do not have space delimiters - the strings
can span multiple words, etc.
"Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx> wrote in message
news:op.t7lw7dew8jd0ej@xxxxxxxxxxxxxxxxxxxxxxx
On Thu, 06 Mar 2008 10:08:22 -0800, Karch <news.microsoft.com> wrote:
I think the StateGraph approach is going to work best. I have an
implementation up and running and should be able to get some timings done
today.
Have you tried the dictionary approach suggested by a couple of others?
I wasn't paying attention when I first read your question and failed to
note that your search is delimited by spaces. Or, at least in the
examples you provided it was.
I think that if your data is actually restricted like that, the dictionary
lookup might be as fast as a state graph and it would be a lot simpler in
terms of implementation.
Just a thought. Obviously I really like state graphs :), but when there
is information you know about the input data that allows you to constrain
the problem a bit (e.g. by using spaces to identify the beginning and
ending of any possible match), it's often possible to solve the problem
efficiently without using a state graph.
Pete
.
- Follow-Ups:
- Re: Fast way to determine if a string contains a member of a list of strings
- From: Peter Duniho
- Re: Fast way to determine if a string contains a member of a list of strings
- References:
- Prev by Date: Re: Bizarre benchmark result -- C# hundreds of times slower than Java?
- Next by Date: Re: Namespaces and Inheritance
- Previous by thread: Re: Fast way to determine if a string contains a member of a list of strings
- Next by thread: Re: Fast way to determine if a string contains a member of a list of strings
- Index(es):
Relevant Pages
|