Hi again,
recently i "attended" a streamed webcast from micrsoft .NET shop. called Code Optimization from September 10. 2002.
In here there talking about how the GC works and what is do'es and don'ts for programming .net.
To my suprise you can hear Gregor Noriskin (Performance Program manager for the CLR team at Microsoft) state that this code construct is fairly expensive
This is quite a nice looking approach to having fairly self documenting code but it turns out that the CLR is far better optimized for executing this code:
In essense the same semantics with a different syntax. But a huge difference. It turns out that the difference is at least a factor 2. Foreach is takes doubble the time to execute in comparison with the old for style looping. And this regardless of the count of elements in the collection.
This might not seem like a lot, but looking at the MP code today at least 124 source code files contains one or multiple foreach'es some of them might even be nested.
I know this could turn out to be nearly not measureable, but it's something to take into account.
Who knows changing them all might give stunning results !!!!
Interested check the cast here: http://msdn.microsoft.com/theshow/Episode027/default.asp
The last thing i'd like to point out is the Splash.cs. From main the constructor calls both the SetInformation and SetVersion methods. Both of these Yields an Update (redraw). And the constructor itself is only called from Main in this construct:
To prove my point I've tried to write down the execution sequence here:
This isn't much but it's some...
Happy coding,
Ojo
recently i "attended" a streamed webcast from micrsoft .NET shop. called Code Optimization from September 10. 2002.
In here there talking about how the GC works and what is do'es and don'ts for programming .net.
To my suprise you can hear Gregor Noriskin (Performance Program manager for the CLR team at Microsoft) state that this code construct is fairly expensive
Code:
int id=0;
// al being a collection of ints. In this case an ArrayLists of ints
foreach (int i in al)
{
// some computation using
id = i;
}
This is quite a nice looking approach to having fairly self documenting code but it turns out that the CLR is far better optimized for executing this code:
Code:
int id=0;
int c = al.Count;
for (int i=0; i < c; i++)
{
id = (int) al[i];
}
In essense the same semantics with a different syntax. But a huge difference. It turns out that the difference is at least a factor 2. Foreach is takes doubble the time to execute in comparison with the old for style looping. And this regardless of the count of elements in the collection.
This might not seem like a lot, but looking at the MP code today at least 124 source code files contains one or multiple foreach'es some of them might even be nested.
I know this could turn out to be nearly not measureable, but it's something to take into account.
Who knows changing them all might give stunning results !!!!
Interested check the cast here: http://msdn.microsoft.com/theshow/Episode027/default.asp
The last thing i'd like to point out is the Splash.cs. From main the constructor calls both the SetInformation and SetVersion methods. Both of these Yields an Update (redraw). And the constructor itself is only called from Main in this construct:
Code:
splashScreen = new SplashScreen();
splashScreen.SetVersion(clientInfo .InstalledVersion);
splashScreen.Show();
splashScreen.Update();
To prove my point I've tried to write down the execution sequence here:
Code:
splashScreen = new SplashScreen();
// splash constructor
...
SetInformation("Loading...");
// Yields an Update()
SetVersion(Application.ProductVersion);
// Yields an Update()
// end splash constructor
splashScreen.SetVersion(clientInfo .InstalledVersion);
// Updates the version again and
// Yields yet another Update()
splashScreen.Show();
// The only Update needed as far as I can tell
splashScreen.Update();
This isn't much but it's some...
Happy coding,
Ojo