No braces don't effect runtime performance at all.  They are a language
thing and don't survive the compilation to IL code.

Write a class with these methods...

                public void foo()
                {
                        for (int i = 0; i < 100000; ++i)
                                Console.WriteLine("foo");
                }

                public void bar()
                {
                        for (int i = 0; i < 100000; ++i)
                        {
                                Console.WriteLine("bar");
                        }
                }

Run ildams.exe and load your assembly.  Inspect the methods and notice
that exactly the same IL is produced.  That code is compiled into native
x86 instructions at runtime so given the same IL the same x86
instructions should be generated and the code for both methods should be
the same.


Jim Murphy
Mindreef, LLC
http://www.mindreef.com




> -----Original Message-----
> From: Moderated discussion of advanced .NET topics. [mailto:ADVANCED-
> [EMAIL PROTECTED]] On Behalf Of Edward Ferron
> Sent: Wednesday, January 22, 2003 1:06 PM
> To: [EMAIL PROTECTED]
> Subject: [ADVANCED-DOTNET] Braces make code execution faster?
>
> I am using the NuMega/Compuware Truetime tool to measure performance
in a
> simple console application.  I have tested the following code several
> times
> with consistent results
>
> // The following code is faster
>
> for(int i = 0; i < 10000; ++i)
> {
>   // do anything here ... Console.WriteLine, assign i to another
variable,
> it doesn't matter....
> }
>
>
> // than this code
>
>
> for (int = i; i < 10000; ++i)
>   // do anything here ... Console.WriteLine, assign i to another
variable,
> it doesn't matter....
>
>
> Do the braces speed up code execution?  Why/how?
>
> You can read messages from the Advanced DOTNET archive, unsubscribe
from
> Advanced DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to