主题:【原创】说说.NET 3.5中的高性能害死集--HashSet -- Highway
共:💬19 🌺63
我使用了不同的Heap Size,结果大差不差。看样子GC不是一个主要因素。我甚至把程序放到了64位的Linux机器上,结果也还是没什么变化。
测试结果我感觉和HashMap的具体实现有关系。你看看Sun的这段文档。
An instance of HashMap has two parameters that affect its performance: initial capacity and load factor. The capacity is the number of buckets in the hash table, and the initial capacity is simply the capacity at the time the hash table is created. The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the capacity is roughly doubled by calling the rehash method. As a general rule, the default load factor (.75) offers a good tradeoff between time and space costs. Higher values decrease the space overhead but increase the lookup cost (reflected in most of the operations of the HashMap class, including get and put). The expected number of entries in the map and its load factor should be taken into account when setting its initial capacity, so as to minimize the number of rehash operations. If the initial capacity is greater than the maximum number of entries divided by the load factor, no rehash operations will ever occur. If many mappings are to be stored in a HashMap instance, creating it with a sufficiently large capacity will allow the mappings to be stored more efficiently than letting it perform automatic rehashing as needed to grow the table.
- 相关回复 上下关系8
🙂【致歉】Highway向大家道个歉 9 Highway 字1520 2007-09-09 19:28:35
😄俺这个计算机小白看不懂也送花 马鹿 字0 2007-09-05 22:21:19
🙂JAVA 和.NET 再整数上的速度差有没有可能是heap 的 1 虹道 字150 2007-09-05 21:51:35
😉Good Question。为了回答你这个问题,
🙂如果把HashMap的起始容量加大 虹道 字47 2007-09-08 15:15:50
🙂很有道理 tkvn 字457 2007-09-06 09:00:25
🙂C#不需要collect garbage么? 请尽量 字0 2007-09-05 22:34:18
😉需要。.NET和Java在这个问题上完全一样 1 Highway 字306 2007-09-05 22:44:50