<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: A Fast Equals() &#8211; Remember to Always Measure</title>
	<atom:link href="http://www.ageektrapped.com/blog/a-fast-equals-remember-to-always-measure/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ageektrapped.com/blog/a-fast-equals-remember-to-always-measure/</link>
	<description>Trapped online since 2004</description>
	<lastBuildDate>Wed, 07 Jul 2010 03:23:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: jason</title>
		<link>http://www.ageektrapped.com/blog/a-fast-equals-remember-to-always-measure/comment-page-1/#comment-124</link>
		<dc:creator>jason</dc:creator>
		<pubDate>Fri, 29 Feb 2008 01:33:06 +0000</pubDate>
		<guid isPermaLink="false">http://69.42.58.100/~jaso3118/blog/a-fast-equals-remember-to-always-measure/#comment-124</guid>
		<description>First, empty catch blocks are a scourge. They should just be deleted and the consequences dealt with. Unfortunately, the coder who deleted the useless catch block will be assigned the bug, not the lazy idiot who put it there in the first place. I ran into that today, so it&#039;s fresh in my mind. :)

Checking for null is probably much faster when you think about it: you&#039;re checking references, whereas catching anything requires gathering stack info, creating an exception instance and then throwing it, and then popping the call stack until it&#039;s caught and running all the finally blocks.

Also, checking for null is such a common occurrence, I suspect MS did something deep down in the CLR to optimize that, not that it needs that much optimizing, it&#039;s just checking addresses. 

I got tired of having all strings be non-null in our app so I did some digging and found that checking an empty string for null and empty is faster that checking it for just empty. Weird,eh?

Which leads me to the second thing you&#039;re looking for: System.Diagnostics.Stopwatch is what I used to measure Equals(). I ran each class through a loop a million times to get some meaningful numbers. You need to run the test enough for the differences show up, but all the details of all that testing is a beyond the scope of a comment, but not a blog post...</description>
		<content:encoded><![CDATA[<p>First, empty catch blocks are a scourge. They should just be deleted and the consequences dealt with. Unfortunately, the coder who deleted the useless catch block will be assigned the bug, not the lazy idiot who put it there in the first place. I ran into that today, so it&#8217;s fresh in my mind. <img src='http://www.ageektrapped.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Checking for null is probably much faster when you think about it: you&#8217;re checking references, whereas catching anything requires gathering stack info, creating an exception instance and then throwing it, and then popping the call stack until it&#8217;s caught and running all the finally blocks.</p>
<p>Also, checking for null is such a common occurrence, I suspect MS did something deep down in the CLR to optimize that, not that it needs that much optimizing, it&#8217;s just checking addresses. </p>
<p>I got tired of having all strings be non-null in our app so I did some digging and found that checking an empty string for null and empty is faster that checking it for just empty. Weird,eh?</p>
<p>Which leads me to the second thing you&#8217;re looking for: System.Diagnostics.Stopwatch is what I used to measure Equals(). I ran each class through a loop a million times to get some meaningful numbers. You need to run the test enough for the differences show up, but all the details of all that testing is a beyond the scope of a comment, but not a blog post&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gfox</title>
		<link>http://www.ageektrapped.com/blog/a-fast-equals-remember-to-always-measure/comment-page-1/#comment-123</link>
		<dc:creator>gfox</dc:creator>
		<pubDate>Thu, 28 Feb 2008 22:43:09 +0000</pubDate>
		<guid isPermaLink="false">http://69.42.58.100/~jaso3118/blog/a-fast-equals-remember-to-always-measure/#comment-123</guid>
		<description>So what is the best way to measure?  I came across some crappy code in our codebase that seemed to always throw exceptions which were caught with an empty handler.  The intent was to use the default behaviour for exceptions.

I found that a lower level object was null quite a lot, so instead of the exception handling, I added a test for null.  I tried adding some time measurements, but they always returned 0 milliseconds.

I used the TimeSpan class and was looking at TotalMilliseconds.  Both seemed equally fast, yet I seem to remember reading somewhere that exceptions like this took longer than checking for null (makes sense to me any way).

Thoughts?</description>
		<content:encoded><![CDATA[<p>So what is the best way to measure?  I came across some crappy code in our codebase that seemed to always throw exceptions which were caught with an empty handler.  The intent was to use the default behaviour for exceptions.</p>
<p>I found that a lower level object was null quite a lot, so instead of the exception handling, I added a test for null.  I tried adding some time measurements, but they always returned 0 milliseconds.</p>
<p>I used the TimeSpan class and was looking at TotalMilliseconds.  Both seemed equally fast, yet I seem to remember reading somewhere that exceptions like this took longer than checking for null (makes sense to me any way).</p>
<p>Thoughts?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
