Re: What if structure is faster? or not?>

From: EijiTek (eijitek_at_comcast.net)
Date: 07/07/04


Date: Tue, 6 Jul 2004 21:37:57 -0500


>From looking at the intermediate language for a similar example there is
very little difference between the two. Any difference between the two is
negligible in terms of performance.

I've included the IL from my test as an example so you can see what's going
on behind the scenes. You can see that the first type (if...else) branches
if the condition is false loads the string (True!), assigns it, then
branches out of the statement or (if the condition was false) loads the
string (False!), assigns it, and continues execution. The second type
(ternary operator) branches if the condition is true, loads the false string
then branches to the assignment otherwise if the condition was true it loads
the true string and assigns it. Long story short, we're talking about one
line IL more in the if...else version.

.method public hidebysig static void Main() cil managed
{
  .entrypoint
  // Code size 48 (0x30)
  .maxstack 2
  .locals init (bool V_0,
           string V_1,
           string V_2)
  IL_0000: ldc.i4.1
  IL_0001: stloc.0
  IL_0002: ldloc.0
  IL_0003: brfalse.s IL_000d
  IL_0005: ldstr "True!"
  IL_000a: stloc.1
  IL_000b: br.s IL_0013
  IL_000d: ldstr "False!"
  IL_0012: stloc.1
  IL_0013: ldloc.1
  IL_0014: call void [mscorlib]System.Console::WriteLine(string)
  IL_0019: ldloc.0
  IL_001a: brtrue.s IL_0023
  IL_001c: ldstr "False!"
  IL_0021: br.s IL_0028
  IL_0023: ldstr "True!"
  IL_0028: stloc.2
  IL_0029: ldloc.2
  IL_002a: call void [mscorlib]System.Console::WriteLine(string)
  IL_002f: ret
} // end of method TestApplication::Main



Relevant Pages

  • Re: XML whackyness
    ... oDOM.Load loads the file directly, whereas oDOM.LoadXML loads a string. ... It is essential you don't try and read the XML file manually and then pass ... magic bytes and know to treat the xml data as being in the utf-8 character ...
    (microsoft.public.vb.general.discussion)
  • Re: Find string in Data
    ... Do I have the parts in brackets after the sub name? ... Sorry for this but thanks loads for your help so far. ... Sub GetAssignments(Cell As Range, Phrase As String) ... we did have a problem cancelling in the system (see my note ...
    (microsoft.public.excel.programming)
  • Re: What if structure is faster? or not?>
    ... > From looking at the intermediate language for a similar example there is ... You can see that the first type ... > branches out of the statement or loads the ... > string, assigns it, and continues execution. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Error msg
    ... Expand the branches to reach ... pane for the string that loads defolder.exe. ... just need to remove the registry entry that loads it. ... Windows help - www.rickrogers.org ...
    (microsoft.public.windowsxp.general)
  • Re: FormsAuthentication.HashPasswordForStoringInConfigFile
    ... .method public hidebysig static string ... IL_0008: newobj instance void ... IL_0072: call string ... Jerry ...
    (microsoft.public.dotnet.framework)