开发者

Predicting Dictionary<> size and speed

开发者 https://www.devze.com 2023-04-08 14:49 出处:网络
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

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.

Predicting Dictionary<> size and speed

Details of the test and results at http://blog.tedd.no/2011/09/26/net-dictionary-speed-and-memory/

0

精彩评论

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

关注公众号