Friday, September 09, 2005

With the recent changes to Nullables in v2.0, I wanted to go back to some old tests that had not been very satisfying when I ran them over a year ago.

One was comparing the speed of using a Nullable<T> and testing to see if has a value or not with HasValue to the speed of a just checking for either a null or default value in a system.type.

Here were my results from doing this in July 2004

You will see that a Nullable<Int32> test was much slower than Int32>0 and a Nullable<object> test was slower than object = = null (or IsNull in VB).

Now with the August 05 CTP, things have sped up. One thing to note is that you can't use Nullable<T> with already nullable values as you could before. So now I am only testing against int.

Using the same 500,000 interations with a Nullable<int>, although the  gap is shrinking, is still somewhat slower. Three tests gave these results

  • Nullable<int>.HasValue   vs. int>0
  • 4.7668 ms       3.2459 ms
  • 5.9834 ms       3.4426 ms
  • 4.0203 ms        3.8122 ms

Still, I much prefer Nullable<T> over the other test. What do you test for with dates?



Don't Forget: www.acehaid.org
Friday, September 09, 2005 1:31:57 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview