这是更快:联盟或Concat的? [英] Which is faster: Union or Concat?

查看:97
本文介绍了这是更快:联盟或Concat的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不关心元素的顺序。

<一个href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.union.aspx">http://msdn.microsoft.com/en-us/library/system.linq.enumerable.union.aspx

<一个href="http://msdn.microsoft.com/en-us/library/bb302894.aspx">http://msdn.microsoft.com/en-us/library/bb302894.aspx

推荐答案

联盟删除重复。 CONCAT没有。

Union removes duplicates. Concat does not.

于是,他们产生不同的结果,如果源或者包含共同的任何物品,或有任何内部副本。

So, they produce different results if the sources either contain any items in common, or have any internal duplicates.

如果你能保证没有重复,或者有一些你不关心让他们在你的输出,Concat的速度会更快,因为没有必要测试的东西已经产生了每个值。

If you can guarantee there are no duplicates, or if there are few and you don't care about having them in your output, Concat will be faster since there's no need to test each value against what has already been yielded.

但是,如果有很多重复的,你不需要他们,在联盟的额外处理以去除易受骗的人可能是由消耗的结果节省您的code抵消。

However, if there are many duplicates and you don't need them, the extra processing in Union to remove the dupes may be offset by the savings in your code that consumes the results.

这篇关于这是更快:联盟或Concat的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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