C#FindAll VS哪里速度 [英] C# FindAll VS Where Speed

查看:171
本文介绍了C#FindAll VS哪里速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道Where和ListAll之间的速度差异。我知道IEnumerable的一部分在哪里,而FindAll是List的一部分,我只是想知道什么更快。

Anyone know any speed differences between Where and FindAll on List. I know Where is part of IEnumerable and FindAll is part of List, I'm just curious what's faster.

推荐答案

FindAll方法列表< T>中的类实际上构造了一个新的列表对象,并向其添加结果。 IEnumerable< T>的Where扩展方法是:将简单地遍历现有列表并产生匹配结果的枚举,而不创建或添加任何内容(枚举器本身除外。)

The FindAll method of the List<T> class actually constructs a new list object, and adds results to it. The Where extension method for IEnumerable<T> will simply iterate over an existing list and yield an enumeration of the matching results without creating or adding anything (other than the enumerator itself.)

给出一小部分,这两个可能会比较。但是,给定一个更大的集合,其中Where应该胜过FindAll,因为为包含结果而创建的新List将必须动态增长以包含其他结果。

Given a small set, the two would likely perform comparably. However, given a larger set, Where should outperform FindAll, as the new List created to contain the results will have to dynamically grow to contain additional results. Memory usage of FindAll will also start to grow exponentially as the number of matching results increases, where as Where should have constant minimal memory usage (in and of itself...excluding whatever you do with the results.)

这篇关于C#FindAll VS哪里速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆