Click here to Skip to main content
16,007,885 members
Home / Discussions / C#
   

C#

 
GeneralRe: Cryptographic question Pin
DaveyM6913-Feb-08 4:03
professionalDaveyM6913-Feb-08 4:03 
GeneralRe: Cryptographic question Pin
User 665813-Feb-08 4:35
User 665813-Feb-08 4:35 
GeneralRe: Cryptographic question Pin
Todor A Kolev13-Feb-08 20:07
Todor A Kolev13-Feb-08 20:07 
GeneralRe: Cryptographic question Pin
Mark Churchill14-Feb-08 1:18
Mark Churchill14-Feb-08 1:18 
GeneralPerforming method of a class contained in a generic list without foreach Pin
DaveyM6913-Feb-08 3:28
professionalDaveyM6913-Feb-08 3:28 
GeneralRe: Performing method of a class contained in a generic list without foreach Pin
Judah Gabriel Himango13-Feb-08 8:40
sponsorJudah Gabriel Himango13-Feb-08 8:40 
GeneralRe: Performing method of a class contained in a generic list without foreach Pin
DaveyM6913-Feb-08 9:12
professionalDaveyM6913-Feb-08 9:12 
GeneralRe: Performing method of a class contained in a generic list without foreach Pin
Judah Gabriel Himango13-Feb-08 11:38
sponsorJudah Gabriel Himango13-Feb-08 11:38 
LINQ is using lambda expressions as well. A lambda is essentially just a function you pass into another function. Both examples I gave were using lambdas under the hood.

The reason the List<T> methods may be slightly faster is because they've tuned it to a specific implementation (which is an array under the hood). The LINQ stuff might work slower because it doesn't know about any specific implementation; all it knows about is that it's working on IEnumerable<T>, which means it have to use a foreach to iterate over it, which is fast, but perhaps not as fast as List<T> highly optimized implementation as you point out.

Another thing to keep in mind is that because LINQ is declarative, it opens up real big optimizations that can happen under the hood. For example, say you have a quad processor. Given the following code:

var listViewItems = from movie in dvds.AsParallel() // AsParallel is a PLINQ extension method
                    where movie.ID > 0 
                    select movie.ToCustomListViewItem();

Your query will now run approximately 4 times as fast as your List<T>.FindAll call, thanks to multiple cores. And since we'll be seeing more and more cores in the future, the above query will keep running faster and faster the more cores become available, with no extra work on your part. (A MS guy recently said Intel supplied them with an experimental 32-core desktop processor. When the day comes that we're all running 32 core processors, the above code will run about 32x as fast as List<T>.FindAll.)

.....Now, in regards to optimizing your code....

30% sounds good, but it may not be that big in practice. For example, if a foreach over your DVD collection takes 10 milliseconds, and a List<T>.Findall takes only 7 milliseconds, that's a 30% difference, but that's an indistinguishable 3 milliseconds to the end user. Big woop. Unless that code is in a hot loop being called millions of times, it makes no difference whether you use foreach, LINQ, or some List<T> method call.

My advice is this: make your code readable before doing optimizations, and optimize only the stuff that really matters. In this case, List<T>.FindAll and List<T>.ConvertAll is only slightly less readable than the LINQ version, so do what you please. But bear in mind, these kind of micro-optimizations are more or less worthless -- it's much more important to write easily-readable code.





Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Upon this disciple I'll build my new religion?
The apostle Paul, modernly speaking: Epistles of Paul

Judah Himango


GeneralRe: Performing method of a class contained in a generic list without foreach Pin
DaveyM6913-Feb-08 12:18
professionalDaveyM6913-Feb-08 12:18 
GeneralRe: Performing method of a class contained in a generic list without foreach [modified] Pin
DaveyM6913-Feb-08 12:30
professionalDaveyM6913-Feb-08 12:30 
GeneralRe: Performing method of a class contained in a generic list without foreach Pin
Judah Gabriel Himango14-Feb-08 4:30
sponsorJudah Gabriel Himango14-Feb-08 4:30 
QuestionWPF RichTextBox Formatted Data Sent to Access Database Pin
Thomas Stockwell13-Feb-08 3:28
professionalThomas Stockwell13-Feb-08 3:28 
GeneralRe: WPF RichTextBox Formatted Data Sent to Access Database Pin
Giorgi Dalakishvili13-Feb-08 4:05
mentorGiorgi Dalakishvili13-Feb-08 4:05 
GeneralRe: WPF RichTextBox Formatted Data Sent to Access Database Pin
Thomas Stockwell13-Feb-08 8:12
professionalThomas Stockwell13-Feb-08 8:12 
GeneralRe: WPF RichTextBox Formatted Data Sent to Access Database Pin
Giorgi Dalakishvili13-Feb-08 8:51
mentorGiorgi Dalakishvili13-Feb-08 8:51 
GeneralRe: WPF RichTextBox Formatted Data Sent to Access Database Pin
Thomas Stockwell13-Feb-08 13:00
professionalThomas Stockwell13-Feb-08 13:00 
Generalthread Pin
248912813-Feb-08 2:58
248912813-Feb-08 2:58 
GeneralRe: thread Pin
Not Active13-Feb-08 3:12
mentorNot Active13-Feb-08 3:12 
GeneralRe: thread Pin
Bekjong13-Feb-08 3:19
Bekjong13-Feb-08 3:19 
GeneralRe: thread Pin
Spacix One13-Feb-08 5:08
Spacix One13-Feb-08 5:08 
GeneralAbnormal thread results Pin
Yoyosch13-Feb-08 2:21
Yoyosch13-Feb-08 2:21 
GeneralRe: Abnormal thread results Pin
Bekjong13-Feb-08 3:01
Bekjong13-Feb-08 3:01 
GeneralRe: Abnormal thread results Pin
CKnig13-Feb-08 3:02
CKnig13-Feb-08 3:02 
GeneralRe: Abnormal thread results [modified] Pin
Yoyosch13-Feb-08 3:16
Yoyosch13-Feb-08 3:16 
GeneralThreadding Issue Pin
Harvey Saayman13-Feb-08 1:40
Harvey Saayman13-Feb-08 1:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.