慢linq查询 [英] slow linq query

查看:65
本文介绍了慢linq查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我正在做以下事情,这是一个音频文件列表。


this.Where(p = p.Album == AnAudioFileObject.Album)。选择(s =>

s.Artist).Distinct()。Count()1;


目的是确定AnAudioFileObject是否来自一张专辑,其中
上有各种艺术家或者只有一位艺术家。


如果我加载数千个音频文件这个名单变得非常好了很多,有没有人会想到一种可以加快速度的方法?


任何帮助都会受到赞赏。


-

Eps

Hi there,

I am doing the following, this is a List of audio files.

this.Where(p =p.Album == AnAudioFileObject.Album).Select(s =>
s.Artist).Distinct().Count() 1;

The aim is to determine whether AnAudioFileObject is from an album that
has various artists on it or just one artist.

If I load several thousand audio files into the list it becomes very
slow, can anyone think of a way I could speed this up ?.

Any help appreciated.

--
Eps

推荐答案

怎么样


if(this.Any(p = p.Album == AnAudioFileObject.Album)){..}


? :-)


-

关于

Anders Borum / SphereWorks

微软认证专家(.NET MCP)
How about

if (this.Any(p =p.Album == AnAudioFileObject.Album)) { .. }

? :-)

--
With regards
Anders Borum / SphereWorks
Microsoft Certified Professional (.NET MCP)


Eps< ep*@mailinator.comwrote:
Eps <ep*@mailinator.comwrote:

我正在做下面,这是一个音频文件列表。


this.Where(p = p.Album == AnAudioFileObject.Album)。选择(s =>

s.Artist).Distinct()。Count()1;


目的是确定AnAudioFileObject是否来自一张专辑

有各种各样的上面的艺术家或者只是一位艺术家。


如果我将几千个音频文件加载到列表中它会变得非常好b / b
慢,有人能想到我的方式吗?可以加快速度吗?。


任何帮助表示感谢。
I am doing the following, this is a List of audio files.

this.Where(p =p.Album == AnAudioFileObject.Album).Select(s =>
s.Artist).Distinct().Count() 1;

The aim is to determine whether AnAudioFileObject is from an album that
has various artists on it or just one artist.

If I load several thousand audio files into the list it becomes very
slow, can anyone think of a way I could speed this up ?.

Any help appreciated.



你能给出几千的确切数字吗?和非常慢?

就我所知,所有这些应该是线性操作,所以它可能是其他东西正在发生的事情。


你能发一个简短但完整的程序来演示

的问题吗?


http://www.pobox.com/~skeet/csharp/complete.html 详细信息

我的意思是什么。


-

Jon Skeet - < sk * **@pobox.com>

网站: http:/ /www.pobox.com/~skeet

博客: http://www.msmvps.com/jon.skeet

C#深度: http://csharpindepth.com

Could you give definite figures for "several thousand" and "very slow"?
All of those should be linear operations as far as I''m aware, so it''s
possible something else is going on.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com


Anders Borum写道:
Anders Borum wrote:

怎么样


if(this.Any(p = p.Album == AnAudioFileObject.Album)){..}

? :-)
How about

if (this.Any(p =p.Album == AnAudioFileObject.Album)) { .. }

? :-)



嗯,以编程方式用linq和另一半做一半吗?。


我以为linq和程序化迭代的速度大致相当于两个人之间的速度,两者混合的优势是什么?


刚发布后我意识到我可以这样做......


this.Where(p = p.Album == AnAudioFileObject.Album)。取(2)。选择(s =>

s.Artist).Distinct()。Count()1;


Take(2)确实对速度产生了重大影响,它不是

理想,因为有各种艺术家的专辑确实具有两次(或更多次)

相同的艺术家,但出于我的目的,我认为它会没问题。

-

Eps

hmmm, do half of it with it linq and the other half programmatically ?.

I thought that linq and programmatic iteration were roughly about as
fast as each other, whats the advantage of mixing the two ?.

Just after I posted I realized I could do this...

this.Where(p =p.Album == AnAudioFileObject.Album).Take(2).Select(s =>
s.Artist).Distinct().Count() 1;

The Take(2) does seem to have a significant impact on the speed, its not
ideal since there are albums with various artists that do feature the
same artist twice (or more times) but for my purposes I think it will be ok.

--
Eps


这篇关于慢linq查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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