.net - HashSet<T> 与 Dictionary<K, V> 相对于查找项目是否存在的搜索时间

标签 .net performance dictionary hashset

HashSet<T> t = new HashSet<T>();
// add 10 million items


Dictionary<K, V> t = new Dictionary<K, V>();
// add 10 million items.

谁的 .Contains 方法返回速度更快?

澄清一下,我的要求是我有 1000 万个对象(实际上是字符串),我需要检查它们是否存在于数据结构中。我永远不会迭代。

最佳答案

HashSet vs List vs Dictionary 性能测试,摘自here .

添加 1000000 个对象(不检查重复项)

包含检查 10000 个集合中一半的对象

删除 10000 个集合中的一半对象

关于.net - HashSet<T> 与 Dictionary<K, V> 相对于查找项目是否存在的搜索时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2728500/

相关文章:

c++ - 在 std::map<..., boost::any> 中初始化子图

.net - 是否可以在将自身指定为泛型类型参数的同时发出从泛型类型派生的类型?

.net - Visual Studio 和 .NET 编程

java - 我们是否需要使用 MappedByteBuffer.force() 将数据刷新到磁盘?

python - 将嵌套的 html 表转换为 python 中的嵌套字典?

python - Pandas 列内的映射值

.net - 从 Internet Explorer 检索所有 cookie

.net - 如何从 WPF 应用程序中的标准输入读取内容?

python - python 中大型列表操作的性能更高

sql - 为什么 CTE(递归)没有并行化(MAXDOP=8)?