Click here to Skip to main content
15,886,199 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: CCC 01-06-2022 Pin
Kornfeld Eliyahu Peter31-May-22 23:55
professionalKornfeld Eliyahu Peter31-May-22 23:55 
GeneralRe: CCC 01-06-2022 Pin
OriginalGriff1-Jun-22 0:15
mveOriginalGriff1-Jun-22 0:15 
GeneralRe: CCC 01-06-2022 Pin
Richard MacCutchan1-Jun-22 0:48
mveRichard MacCutchan1-Jun-22 0:48 
GeneralRe: CCC 01-06-2022 Pin
Craig Robbins1-Jun-22 1:21
Craig Robbins1-Jun-22 1:21 
GeneralRe: CCC 01-06-2022 Pin
OriginalGriff1-Jun-22 1:39
mveOriginalGriff1-Jun-22 1:39 
GeneralRe: CCC 01-06-2022 Pin
OriginalGriff1-Jun-22 1:16
mveOriginalGriff1-Jun-22 1:16 
GeneralRe: CCC 01-06-2022 - Winner !!! Pin
pkfox1-Jun-22 1:53
professionalpkfox1-Jun-22 1:53 
Generalblind micro optimisation Pin
Super Lloyd31-May-22 18:20
Super Lloyd31-May-22 18:20 
on a code review someone commented I was enumerating twice a really big list, could I have only one loop instead, they said

initial code, where source is a large list
C#
list.AddRange(source.OfType<A>());
DoThings(source.OfType<B>());

void DoThings(IEnumerable<B> items)
{
  foreach (var b in item)
  {
    // do something
  }
}

so to please the crowd I refactored
new code
C#
foreach (var item in source)
{
  if (item is A a)
    list.Add(a);
  if (item is B b)
    DoThing(b);
}
void DoThings(IEnumerable<B> items) // still in use through an other codepath
{
  foreach (var b in item)
    DoThing(b);
}
void DoThing(B b)
{
  // do something
}

now... without doing any measurement (hence the blind adjective) I am suspecting version 2 is in fact slower, since enumerating is cheap, but there a lot more method calls.

What says you?
A new .NET Serializer
All in one Menu-Ribbon Bar
Taking over the world since 1371!


modified 1-Jun-22 7:01am.

GeneralRe: blind micro optimisation Pin
CodeWomble31-May-22 19:40
CodeWomble31-May-22 19:40 
GeneralRe: blind micro optimisation Pin
Super Lloyd31-May-22 20:12
Super Lloyd31-May-22 20:12 
GeneralRe: blind micro optimisation Pin
dan!sh 31-May-22 21:16
professional dan!sh 31-May-22 21:16 
GeneralRe: blind micro optimisation Pin
lmoelleb31-May-22 23:06
lmoelleb31-May-22 23:06 
GeneralRe: blind micro optimisation Pin
Super Lloyd31-May-22 23:17
Super Lloyd31-May-22 23:17 
GeneralRe: blind micro optimisation Pin
megaadam31-May-22 23:39
professionalmegaadam31-May-22 23:39 
GeneralRe: blind micro optimisation Pin
Richard Deeming1-Jun-22 0:23
mveRichard Deeming1-Jun-22 0:23 
GeneralRe: blind micro optimisation Pin
jsc421-Jun-22 0:27
professionaljsc421-Jun-22 0:27 
GeneralRe: blind micro optimisation Pin
Richard Deeming1-Jun-22 0:35
mveRichard Deeming1-Jun-22 0:35 
GeneralRe: blind micro optimisation Pin
PIEBALDconsult1-Jun-22 2:43
mvePIEBALDconsult1-Jun-22 2:43 
GeneralRe: blind micro optimisation Pin
Super Lloyd1-Jun-22 17:33
Super Lloyd1-Jun-22 17:33 
GeneralRe: blind micro optimisation Pin
honey the codewitch1-Jun-22 2:58
mvahoney the codewitch1-Jun-22 2:58 
GeneralRe: blind micro optimisation Pin
Super Lloyd1-Jun-22 17:32
Super Lloyd1-Jun-22 17:32 
GeneralRe: blind micro optimisation Pin
obermd2-Jun-22 3:12
obermd2-Jun-22 3:12 
GeneralRe: blind micro optimisation Pin
honey the codewitch3-Jun-22 3:09
mvahoney the codewitch3-Jun-22 3:09 
GeneralRe: blind micro optimisation Pin
Super Lloyd4-Jun-22 6:21
Super Lloyd4-Jun-22 6:21 
GeneralRe: blind micro optimisation Pin
honey the codewitch4-Jun-22 6:48
mvahoney the codewitch4-Jun-22 6:48 

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.