It's well known that braces speed up code. That's why VB has always been
slower and while K&R chose to ape B when developing C (and why
Stroustrup continued the tradition). In fact, check out page 255 in the
D&E [1] where Stroustrup provides a little table showing the speed
increase (between 9-101%, depending on what you're doing). You don't
think that any of us actually *likes* using braces, do you? The VB
syntax is *so* much better, but we avoid it due to the speed-up provided
by braces.

As it turns out, semi-colons are a modest speed-up as well, which is why
the C family of languages uses them as a line termination character
instead of as a line separation character the way that Pascal does.

Chris Sells
http://www.sellsbrothers.com

[1] http://www.amazon.com/exec/obidos/tg/detail/-/0201543303/chrissells

> -----Original Message-----
> From: Moderated discussion of advanced .NET topics. [mailto:ADVANCED-
> [EMAIL PROTECTED]] On Behalf Of Edward Ferron
> Sent: Wednesday, January 22, 2003 10:06 AM
> 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.

Reply via email to