Re: Efficiency of linq expression

Frans Bouma <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <001601c974e0$17be65e0$473b31a0$@nl>
> Wouldn't doing this de-duping in the database be even more efficient?
UNION
> view or something?

	Sure, but it depends on your resources: if you have many clients
running this query, it's perhaps more efficient to do this outside the DB,
as the DB is shared among the many clients and often the clients are
machines with much power to spare. If your system is a website, and many
clients effectively run on the same box, it's indeed perhaps more efficient
to do this in the DB. 

Your routine in the post isn't really efficient as you call Remove on each
iteration which makes it very slow. 

So as you want all mobile users and all landline users not in mobile, you
can do:
return mobile.Union(landLine.Except(mobile));

which should do what you want. (and which uses hashes so it's very
efficient)

	FB

> 
> -----Original Message-----
> From: Discussion of advanced .NET topics. [mailto:ADVANCED-
> [email protected]] On Behalf Of Frans Bouma
> Sent: Sunday, January 11, 2009 7:53 AM
> To: [email protected]
> Subject: Re: [ADVANCED-DOTNET] Efficiency of linq expression
> 
> Use Except()
> 
> (Intersect is its opposite method, they're efficient (done with an
internal
> (why would anyone want to use it, MS?) set class which is similar to a
> hashset))
> 
> 	FB
> 
> > Here is the updated version:
> >
> > public override List<Callee> CalleesForInitialSend() {
> >     var mobile = new List<Callee>(Callees.Where(x => (x is
> > MobileVoiceCallee)));
> >     var landLine = new List<Callee>(Callees.Where(x => (x is
> > LandLineVoiceCallee)));
> >
> >     var union = new List<Callee>();
> >     union.AddRange(mobile);
> >     union.AddRange(landLine);
> >
> >     mobile.Join
> >         (
> >             landLine,
> >             mob => mob.Contact.Uid,
> >             land => land.Contact.Uid,
> >             (m, l) => l
> >         )
> >         .ForEach(x => union.Remove(x));
> >         return union;
> > }
> >
> > 2009/1/11 Paul Cowan <[email protected]>
> >
> > > Hi,
> > >
> > > I have the following method that needs to run as fast as possible
> > > (don't they all).
> > >
> > > I hope it is obvious that I want all mobile users and all landline
> > > users who are not in the mobile list.
> > >
> > > I sincerelly doubt this is as efficient as it could be.
> > >
> > > Maybe somebody can point out a faster way of doing this:
> > >
> > > public override List<Callee> CalleesForInitialSend() {
> > >     var mobile = new List<Callee>(Callees.Where(x => (x is
> > > MobileVoiceCallee)));
> > >     var landLine = new List<Callee>(Callees.Where(x => (x is
> > > LandLineVoiceCallee)));
> > >
> > >     mobile.Join
> > >         (
> > >             landLine,
> > >             mob => mob.Contact.Uid,
> > >             land => land.Contact.Uid,
> > >             (m, l) => l
> > >         )
> > >         .ForEach(x => mobile.Remove(x));
> > >
> > >         return mobile;
> > > }
> > >
> > >
> > >
> >
> > ===================================
> > View archives and manage your subscription(s) at
> > http://peach.ease.lsoft.com/archives
> 
> ===================================
> View archives and manage your subscription(s) at
> http://peach.ease.lsoft.com/archives
> 
> ===================================
> View archives and manage your subscription(s) at
> http://peach.ease.lsoft.com/archives

===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.