home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
Development
General Development (no feature request here!)
Yet a couple of other performance suggestions
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="ojo" data-source="post: 3063" data-attributes="member: 10402"><p>Hi again,</p><p></p><p>recently i "attended" a streamed webcast from micrsoft .NET shop. called Code Optimization from September 10. 2002.</p><p></p><p>In here there talking about how the GC works and what is do'es and don'ts for programming .net.</p><p></p><p>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</p><p></p><p>[code]</p><p> int id=0;</p><p></p><p> // al being a collection of ints. In this case an ArrayLists of ints</p><p> foreach (int i in al) </p><p> {</p><p> // some computation using </p><p> id = i;</p><p> }</p><p></p><p>[/code]</p><p></p><p>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:</p><p></p><p>[code]</p><p> int id=0;</p><p> int c = al.Count;</p><p></p><p> for (int i=0; i < c; i++) </p><p> {</p><p> id = (int) al[i];</p><p> }</p><p></p><p>[/code]</p><p></p><p>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.</p><p></p><p>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.</p><p></p><p>I know this could turn out to be nearly not measureable, but it's something to take into account.</p><p></p><p>Who knows changing them all might give stunning results !!!!</p><p></p><p>Interested check the cast here: <a href="http://msdn.microsoft.com/theshow/Episode027/default.asp" target="_blank">http://msdn.microsoft.com/theshow/Episode027/default.asp</a></p><p></p><p>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:</p><p></p><p>[code]</p><p> splashScreen = new SplashScreen();</p><p> splashScreen.SetVersion(clientInfo .InstalledVersion);</p><p> splashScreen.Show();</p><p> splashScreen.Update();</p><p></p><p>[/code]</p><p></p><p>To prove my point I've tried to write down the execution sequence here:</p><p></p><p>[code]</p><p> splashScreen = new SplashScreen();</p><p> // splash constructor</p><p> ...</p><p> SetInformation("Loading...");</p><p> // Yields an Update()</p><p></p><p> SetVersion(Application.ProductVersion);</p><p> // Yields an Update()</p><p></p><p> // end splash constructor</p><p></p><p> splashScreen.SetVersion(clientInfo .InstalledVersion);</p><p> // Updates the version again and </p><p> // Yields yet another Update()</p><p></p><p> splashScreen.Show();</p><p></p><p> // The only Update needed as far as I can tell</p><p> splashScreen.Update();</p><p></p><p>[/code]</p><p></p><p>This isn't much but it's some...</p><p></p><p>Happy coding,</p><p></p><p>Ojo</p></blockquote><p></p>
[QUOTE="ojo, post: 3063, member: 10402"] 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 [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; } [/code] 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]; } [/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: [url]http://msdn.microsoft.com/theshow/Episode027/default.asp[/url] 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(); [/code] 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(); [/code] This isn't much but it's some... Happy coding, Ojo [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
Development
General Development (no feature request here!)
Yet a couple of other performance suggestions
Contact us
RSS
Top
Bottom