转换IEnumberable< T>列出< T>在LINQ的结果,巨大的性能损失
在一个LINQ的结果,你喜欢这样的:
On a LINQ-result you like this:
var result = from x in Items select x;
List<T> list = result.ToList<T>();
不过,了ToList&LT; T&GT;
实在是太慢了,它榜上无名可变的,因此,转换速度慢?
However, the ToList<T>
is Really Slow, does it make the list mutable and therefore the conversion is slow?
在大多数情况下,我能设法只是我的的IEnumerable
或 Paralell.DistinctQuery
,但现在我想项目绑定到一个DataGridView,所以因此我需要的不是的IEnumerable
,建议我如何将获得的了ToList或更换性能?
In most cases I can manage to just have my IEnumerable
or as Paralell.DistinctQuery
but now I want to bind the items to a DataGridView, so therefore I need to as something else than IEnumerable
, suggestions on how I will gain performance on ToList or any replacement?
在10畅想记录在的IEnumerable
的 .ToList&LT; T&GT;
需要6秒左右。
On 10 milion records in the IEnumerable
, the .ToList<T>
takes about 6 seconds..
.ToList()
是比较慢的什么的?
如果你是比较
var result = from x in Items select x;
List<T> list = result.ToList<T>();
到
var result = from x in Items select x;
您应该注意,由于查询被懒洋洋地评估,第一行并没有做很多的。它不检索任何记录。 延迟执行的使这种比较的完全不公平的的。
you should note that since the query is evaluated lazily, the first line doesn't do much at all. It doesn't retrieve any records. Deferred execution makes this comparison completely unfair.