Re: Compiler optimization, which one is faster? or are they even?

Tech-Archive recommends: Fix windows errors by optimizing your registry



Your second example would be ever so slightly faster on the search as it is
a bit less redirection but would be more costly on adds/deletes. You would
need to be doing alot more searches than updates/deletes to make it faster.

I am sure you have heard the saying "premature optimization is the root of
all evil". This is a great example of such. You are trying to optimize a
very small bit when you should be looking at the algorithm.

Maintaining an index into the original list would be much faster than either
of these as they are both O(n). If your lists are small this doesn't really
matter but if they are large you could do something along the lines of
keeping a table of strings back to their index value ... the two operations
would still generally be much faster than a single O(n) operation.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"ThunderMusic" <NoSpAmdanlatathotmaildotcom@xxxxxxxxxx> wrote in message
news:e5rPqnztGHA.5056@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
How does the .NET compiler optimize it's code?

I have to do searches by a property in a SortedList with a key that is not
the property I have to make my search on.... Is there a performance
difference (in release or debug mode) between those listings? even if the
performance difference is monimal, I want to know which one is best or if
they end up being the same optimized code.

Listing 1:
SortedList<int, Thing> MyThings;
...
...
foreach (Thing TheThing in MyThings)
{
if (TheThing.StringProperty == SomeOtherString)
{
// Do something
}
}

Listing 2:
SortedList<int, Thing> MyThings;
SortedList<int, string> MyThingsStringProperty;
...
// Fill the MyThingsStringProperty once at the beginning and from time to
time when it changes (not very often)
...
...
foreach (string StringProperty in MyThingsStringProperty)
{
if (StringProperty == SomeOtherString)
{
// Do something
}
}

Thanks

ThunderMusic







.



Relevant Pages

  • Re: Compiler optimization, which one is faster? or are they even?
    ... Listing 1: ... if (TheThing.StringProperty == SomeOtherString) ... SortedList<int, string> MyThingsStringProperty; ...
    (microsoft.public.dotnet.framework.performance)
  • Compiler optimization, which one is faster? or are they even?
    ... Listing 1: ... if (TheThing.StringProperty == SomeOtherString) ... SortedList<int, string> MyThingsStringProperty; ...
    (microsoft.public.dotnet.framework.performance)
  • Calling a C function from Java using the JNI
    ... C program from Java to which is I passed a string. ... // Listing 1 ... package com.corejsf; ...
    (comp.lang.java.help)
  • URL Connection Keeps Rereading the same page
    ... Archive.org and give me a listing of the shows and later, ... To get a list of the pages, I create a URL from the String form of the page ... I have a loop that goes through each page and calls a method in another ... The URLConnection is made, as I said, with a method in a different class so ...
    (comp.lang.java.programmer)
  • Re: smart split ?
    ... i am looking for some solution to split a string. ... this} {someotherstring} ... the problem is, i want to split it with comma ... Glenn Jackman ...
    (comp.lang.tcl)