search in a HashTable, DataTable, and XmlDocument, which is faster?

B

Bob

I have a name-value pair type of data that I need to search against. It's
to determine what menu item to highlight given the asp.net page name. So
the list has all my page names (unique) and the corresponding menu IDs.
Some pages have the same menu IDs. One every page load, I want to check the
name, and get the menu ID so the menu can be displayed with the proper items
highlighted. The list various from a couple of dozen entries to a couple of
hundreds of entries depending on the number of pages an app has.

It's pretty easy to implement with either a HashTable, DataTable,
Dictionary, or XmlDocument. Since it's something every page load would hit,
every bit of performance counts. Thanks a lot for any suggestions.

Bob
 
W

William Stacey [MVP]

Would need to test a bit to be sure. A Hybred Hash may be better when the
entries are low and will convert to normal hash when list grows over 10.
This is for speed. Note the speed of lookup will also depend on hash time
for strings. If you can use all lower or upper case, then you don't need a
case insensitive hashcode provider which will save time. Also the length of
strings should be as short as possible as the compare and hash gen will
reflect len of string. If possible, use a number as the key as the compares
and hash are fastest (hash == number value IIRC).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top