English 中文(简体)
C# HashSet<T>搜索性能(与可观测到的Collection<T>比较)?
原标题:C# HashSet<T> search performance (compared to an ObservableCollection<T>)?

C# the general HashSet<T>search exercise should be O(1), and the search exercise of an ObservableCollection<T> should be O(n).

我有许多独特的内容,每个要素都有一个并非独一无二的日间财产。

每一要素仅收回其日期即可计算其哈希姆。 GetHashCode().

现在我想得到我的一组数据,例如,在2012年3月至2012年6月期间有日期的所有要素。

    var result = from p in this.Elements
                 where p.Date >= new DateTime(2012, 03, 01) &&
                       p.Date <= new DateTime(2012, 30, 06
                 select p;

If I run this LINQ query on a collection of 300.000 elements, it takes ~25 ms to return 80 elements that are within the given range - it does not matter if I use a HashSet<T> or an ObservableCollection<T>.

如果我通过所有内容进行人工检查,同时需要大约25个。

但是,我确实知道在一定范围内的所有日期的哈希姆。 能否从我的哈希特和提尔获得所有与上述哈希科德的物品? 我认为,这将大大加快。

是否有可能加速处理准则问题? 我假定,它没有利用我的哈希特和德特的特殊能力?

最佳回答

正如已经指出的,在确定某一特定的散射体是否处于固定状态时,一套散射装置非常有效。 你的问询只是利用了这样一个事实,即散射装置能够在整个设计过程中重复计算,并且进行日期比较。 它根本不会使用 has。 因此,人工方式与查询方式相同。

www.un.org/spanish/ecosoc 你不能从一根 has子中找到一个 element子,你只能检验该 set子的存性。 一位独裁者是你想要的,如果你需要的话(似乎你不喜欢)。

决定你需要与你的数据做些什么,并使用一个选择使用的结构。 这可能是你自己的阶层,他们各自拥有多个内部结构,每个结构在一个方面(例如,寻找范围,另一个由多个领域加以核查),或者可能有一个适合你们需要的现有结构。 但是,如果不知道你想要与你的数据做些什么,那么就很难提供建议。

The other thing to consider is whether you are optimising prematurely. If 25ms to search manually is fast enough then maybe any structure which implements IEnumerable will be good enough. In which case you can choose one based on the other criteria you need.

问题回答

You re not using the right data structure. You should be using something like a sorted list (sorted on the Date property) where you can then binary search for the beginning and end of the range.





相关问题
What to look for in performance analyzer in VS 2008

What to look for in performance analyzer in VS 2008 I am using VS Team system and got the performance wizard and reports going. What benchmarks/process do I use? There is a lot of stuff in the ...

SQL Table Size And Query Performance

We have a number of items coming in from a web service; each item containing an unknown number of properties. We are storing them in a database with the following Schema. Items - ItemID - ...

How to speed up Visual Studio 2008? Add more resources?

I m using Visual Studio 2008 (with the latest service pack) I also have ReSharper 4.5 installed. ReSharper Code analysis/ scan is turned off. OS: Windows 7 Enterprise Edition It takes me a long time ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

热门标签