开发者

asp.net custom resourceprovider using Dictionary / SortedList / SortedDictionary?

开发者 https://www.devze.com 2023-03-29 19:10 出处:网络
This question may have been asked in different formats, but for my current requirement can someone suggest which is the best..

This question may have been asked in different formats, but for my current requirement can someone suggest which is the best..

In ASP.Net i have my own implementation of local & global resources, I'm storing the key value pair in static Dictionary object, Totally there may be a maximum of 10,000 values (all pages). When asp.net application loads a page it stores the value in my static dictionary object. When the page is visited again instead of reading 开发者_C百科the value from resource file it is served from static Dictionary object.

My question is for performance reason Dictionary is the best or should i go with SortedList/ SortedDictionary


Sorting adds overhead, so if you don't need sorting, you're just looking up a single page from the dictionary based on key, then I would stick with the Dictionary.

From you scenario, I assume lookup speed is the most important concern.

SortedDictionary uses a red-black tree, a binary tree that keeps the collection ordered whenever an item is added/deleted. So if you're looking for ranges of values, where the location of one item in the collection relative to another item is important, then SortedDictionary makes sense. Where you might need to access the collection using an index (like an array) instead of the key, SortedList makes sense.

Dictionary uses a hash table to hash and store the keys, which it uses for lookups, so it makes looking up a random, single item very fast. This matches your scenario.

SortedDictionary operates on the order of O(log n) for add/lookup, where Dictionary operates on O(1) for add/lookup.

See a comparison of the System.Collections.Generic collections.

0

精彩评论

暂无评论...
验证码 换一张
取 消