hashmap lookup vs string.contains performance in c#

http://stackoverflow.com/questions/498686/is-string-contains-faster-than-string-indexof

http://theburningmonk.com/2012/05/performance-test-string-contains-vs-string-indexof-vs-regex-ismatch/

http://stackoverflow.com/questions/2856962/sql-vs-hashtable-containskey-vs-string-contains

found only 1 performance benchmark: http://theburningmonk.com/2012/05/performance-test-string-contains-vs-string-indexof-vs-regex-ismatch/

no results for string.contains vs hashtable.Containsvalue performance c#

infact

The Hashtable code is significantly slower than the Dictionary code. I calculate that Hashtable here is 30% slower. This means that for strongly-typed collections, the Dictionary is faster.

http://www.dotnetperls.com/hashtable

 

 

BEST: http://stackoverflow.com/questions/183685/c-sharp-set-collection

Finally, as I have to store a list of values and not key value pairs, I chose to use a HashSet

Sample Code

using (StreamReader srUsersList = new StreamReader(usersListfileName))

{

lock (syncRoot)

{

string tempUsersListString = srUsersList.ReadToEnd().Trim();

 

string[] tempUsersListArray = tempUsersListString.Split(new char[] { ‘,’ }, StringSplitOptions.RemoveEmptyEntries);

usersList = new HashSet<string>(tempUsersListArray);

}

}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s