.net 优化Linq方法
我需要一个新guid中没有的旧guid列表,所以我使用了Contains方法,问题是它已经运行了半个多小时,有没有更快的方法?或者需要多长时间.net 优化Linq方法,.net,vb.net,linq,.net,Vb.net,Linq,我需要一个新guid中没有的旧guid列表,所以我使用了Contains方法,问题是它已经运行了半个多小时,有没有更快的方法?或者需要多长时间 Dim OldGuids As New List(Of Guid) ' 18 million rows Dim NewGuids As New List(Of Guid) ' 6 million rows Dim Filtered = From n In OldGuids Where Not NewGuids.Contains(n) 您应该使用Hash
Dim OldGuids As New List(Of Guid) ' 18 million rows
Dim NewGuids As New List(Of Guid) ' 6 million rows
Dim Filtered = From n In OldGuids Where Not NewGuids.Contains(n)
您应该使用
HashSet
s
然后,您可以编写
OldGuids.IntersectWith(NewGuids)
您应该使用HashSet
s
然后可以编写OldGuids.IntersectWith(NewGuids)
(请注意,这将只返回唯一的元素,如果要保留重复项,这不是您想要的)
var newGuidSet=newhashset(newGuids);
Filtered=OldGuids.Where(g=>!newGuidSet.Contains(g));
(请注意,这将只返回唯一的元素,如果要保留重复项,这不是您想要的)
var newGuidSet=newhashset(newGuids);
Filtered=OldGuids.Where(g=>!newGuidSet.Contains(g));
4月1日?拍摄时间:4月1日?它被占用:它会比contains快得多吗?它会很快,但需要大约400MB或RAM。我得到了系统内存不足的例外,硬盘上有足够的空间。我添加了第二个解决方案,它需要更少的内存。如果这还不够,请切换到64位并下载更多RAM。制作NewGuids
aHashSet
就足以满足您的特定用途,并节省一点内存。它会比contains快得多吗?它会很快,但需要大约400MB或RAM。我发现系统内存不足异常,硬盘上有足够的空间我添加了第二个解决方案,它需要更少的内存。如果这还不够,请切换到64位并下载更多RAM。使NewGuids
aHashSet
满足您的特定用途,并节省一点内存。IntersectWith
在这里没有帮助。您在问题中遗漏了一个not
。应该使用的方法是ExceptWith
,notIntersectWith
IntersectWith
在这里没有帮助。你在问题中漏掉了一个非
。应该使用的方法是ExceptWith
,而不是IntersectWith
Filtered = OldGuids.Except(NewGuids)
var newGuidSet=new HashSet<Guid>(newGuids);
Filtered = OldGuids.Where(g=>!newGuidSet.Contains(g));