I need to accurately calculate the size of a Dictionary for different sizes. I've tried doing some memory monitoring while running my application, but I am doing a lot of other stuff at the same time that affects the result.
How can I calculate (aprox) expected size of a Dictionary with n items? I need to know how much RAM I need in different scenarious.
By what factor does lookup time increase? O(1) ALWAYS?I'm planning to use dictionaries for 10M+ entries, probabl开发者_JAVA技巧y more.
Already consideret question for Size of a dictionary
To answer my own question I created a small test program.
Here are the results:
100 000 random lookups in a table consisting of 10 000 000 random entries takes 0,02 seconds, the table uses 200MB of RAM.
Memory used by a dictionary seems to be around 20-22 times for Int32 index once you get above 100 items. The ratio goes down as the dictionary gets larger.
Pre-allocating memory seems to cut down noticeable on insert time.
Details of the test and results at http://blog.tedd.no/2011/09/26/net-dictionary-speed-and-memory/
精彩评论