<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Profiling with Stopwatch</title><link>http://blogs.msdn.com/shawnhar/archive/2009/07/07/profiling-with-stopwatch.aspx</link><description>.profxcsharpcode, .profxcsharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .profxcsharpcode pre { margin: 0em; } .profxcsharpcode .rem { color:</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Profiling with Stopwatch</title><link>http://blogs.msdn.com/shawnhar/archive/2009/07/07/profiling-with-stopwatch.aspx#9825120</link><pubDate>Thu, 09 Jul 2009 02:54:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9825120</guid><dc:creator>Dominik Dalek</dc:creator><description>&lt;p&gt;What about the perf impact of calling new ProfileMarker() every time? For smaller methods that are executed often in the code this can IMO significantly skew the results (especially on Zune).&lt;/p&gt;</description></item><item><title>re: Profiling with Stopwatch</title><link>http://blogs.msdn.com/shawnhar/archive/2009/07/07/profiling-with-stopwatch.aspx#9825370</link><pubDate>Thu, 09 Jul 2009 05:21:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9825370</guid><dc:creator>ShawnHargreaves</dc:creator><description>&lt;p&gt;&amp;gt; What about the perf impact of calling new ProfileMarker() every time?&lt;/p&gt;
&lt;p&gt;Allocating a 4 byte value type is pretty much insignificant unless the code you are trying profile is incredibly quick (in which case it most likely isn't your hotspot in any case :-)&lt;/p&gt;
</description></item><item><title>re: Profiling with Stopwatch</title><link>http://blogs.msdn.com/shawnhar/archive/2009/07/07/profiling-with-stopwatch.aspx#9825398</link><pubDate>Thu, 09 Jul 2009 05:40:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9825398</guid><dc:creator>gamedboy</dc:creator><description>&lt;p&gt;hi, correct me if I am wrong.&lt;/p&gt;
&lt;p&gt;Since ProfileMarker implement IDisposable,&lt;/p&gt;
&lt;p&gt;there will be a boxing of ProfileMarker when &lt;/p&gt;
&lt;p&gt;Dispose is called?&lt;/p&gt;</description></item><item><title>re: Profiling with Stopwatch</title><link>http://blogs.msdn.com/shawnhar/archive/2009/07/07/profiling-with-stopwatch.aspx#9826874</link><pubDate>Thu, 09 Jul 2009 17:53:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9826874</guid><dc:creator>ShawnHargreaves</dc:creator><description>&lt;p&gt;&amp;gt; Since ProfileMarker implement IDisposable, there will be a boxing of ProfileMarker when Dispose is called?&lt;/p&gt;
&lt;p&gt;No. ProfileMarker is a value type, and is never used polymorphically, so there is no heap allocation or boxing.&lt;/p&gt;
</description></item><item><title>re: Profiling with Stopwatch</title><link>http://blogs.msdn.com/shawnhar/archive/2009/07/07/profiling-with-stopwatch.aspx#9831983</link><pubDate>Mon, 13 Jul 2009 20:39:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9831983</guid><dc:creator>ShadowChaser</dc:creator><description>&lt;p&gt;Most .NET profilers I've used tend to cause the .NET compiler/JITer (or both) to cause issues with optimizations. &lt;/p&gt;
&lt;p&gt;The main issue is structs - given that a game in a tight loop is sensitive to objects created on the heap (later GCed), the use of structs is fairly important. &lt;/p&gt;
&lt;p&gt;I noticed that the XNA framework uses &amp;quot;ref structs&amp;quot; in quite a few places for input only parameters - going against the &amp;quot;spirit&amp;quot; and design guidelines of .NET. Why? .NET doesn't optimize structs properly in the debugger. The same goes with profilers.&lt;/p&gt;
&lt;p&gt;I had &amp;quot;ref structs&amp;quot; all over my game and fairly unreadable code littered everywhere as a result. Ripped them all out and replaced them with the &amp;quot;slower&amp;quot; normal structs. No difference in release mode, but the second I attach a profiler the game slows down by 50% and it shows I'm spending all my time copying structs around on every function call.&lt;/p&gt;
&lt;p&gt;In other words, 99% of the time I end up chasing &amp;quot;Heisenbugs&amp;quot; when profiling XNA games. I really wish the struct issue would be fixed in debug mode, but it's probably for some arcane debugger reason deep in the CLR :(&lt;/p&gt;
&lt;p&gt;The best thing I ever did was follow my guts, use Stopwatch, stop profiling in all but specific cases, and use structs *normally* :) The CLR figures out the best thing to do during Compile time/JIT anyways.&lt;/p&gt;
</description></item><item><title>re: Profiling with Stopwatch</title><link>http://blogs.msdn.com/shawnhar/archive/2009/07/07/profiling-with-stopwatch.aspx#9832524</link><pubDate>Tue, 14 Jul 2009 02:50:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9832524</guid><dc:creator>ShawnHargreaves</dc:creator><description>&lt;p&gt;@ShadowChaser: that sounds like you were using an instrumented profiler (which hooks into the code generation and can alter performance characteristics in a similar way to when a debugger is attached) rather than a sampling profiler (which does slightly slow execution due to the overhead of taking the samples, but is a fixed cost that will not slow one part of your program more than others).&lt;/p&gt;
&lt;p&gt;There is a time and place when instrumented profiling makes sense, but I most often find sampling profilers to be a better starting point.&lt;/p&gt;
&lt;p&gt;Passing large value types by reference can be a very worthwhile optimization when applied in the right places, but it's only worth doing this in critical hotspot code.&lt;/p&gt;
</description></item><item><title>re: Profiling with Stopwatch</title><link>http://blogs.msdn.com/shawnhar/archive/2009/07/07/profiling-with-stopwatch.aspx#9832878</link><pubDate>Tue, 14 Jul 2009 10:45:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9832878</guid><dc:creator>HerrUppoHoppa</dc:creator><description>&lt;p&gt;The only problem I have with this is that the profilers are auto listed on construction but never removed from the list. &lt;/p&gt;
&lt;p&gt;If this were C++ I would just remove it in the destructor, simple and consistent. But since this is managed code and people seem to shun destructors here, how could this be resolved in a good way?&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Pontus Birgersson&lt;/p&gt;</description></item><item><title>re: Profiling with Stopwatch</title><link>http://blogs.msdn.com/shawnhar/archive/2009/07/07/profiling-with-stopwatch.aspx#9833248</link><pubDate>Tue, 14 Jul 2009 18:17:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9833248</guid><dc:creator>ShawnHargreaves</dc:creator><description>&lt;p&gt;@HerrUppoHoppa: the standard pattern in .NET is for things that require deterministic cleanup to implememt IDisposable and do whatever cleanup they need in their Dispose method.&lt;/p&gt;
&lt;p&gt;I didn't bother with that since I never needed to remove profiler instances.&lt;/p&gt;
</description></item><item><title>re: Profiling with Stopwatch</title><link>http://blogs.msdn.com/shawnhar/archive/2009/07/07/profiling-with-stopwatch.aspx#9834381</link><pubDate>Wed, 15 Jul 2009 18:47:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9834381</guid><dc:creator>ShadowChaser</dc:creator><description>&lt;p&gt;@ShawnHargreaves: that makes a lot of sense - all of my profiling had been done using instrumented profilers. Thanks for the great tip - I'll definitely look into sampling profilers a bit more.&lt;/p&gt;
</description></item></channel></rss>