Wednesday, April 27, 2005

 

Nullable Type Performance

David M. Kean has an excellent posting on his blog regarding the performance of Nullable Types in .Net Framework 2.0 Beta 2.

It appears that the summary of the reports would indicate that nullable types can be up to 50% slower (integer types).

However, I tend to agree with some of the comments made on the blog posting. If you prefer to use a nullable data type, is it any slower than implementing your own solution? I have used a custom class called NullableDateTime, which served as a custom solution to the lack of Nullable types in the 1.1 .Net Framework. For quite some time now, I have leaned away from custom nullable types, and instead I default integer variables to -1 to indicate that no value has been assigned. In the case of DateTime types, I simply check to see if the value is greater than DateTime.MinValue. I am not sure I will change my method any time soon.

On the positive side, the post also includes benchmarks for Generic List types. David's testing confirms other reports that Generic List is much faster than an ArrayList. This is primarily due to the need for boxing and un-boxing when using an ArrayList. I have been using Generics for some time and I love them.

Comments: Post a Comment

Links to this post:

Create a Link



<< Home
Content copyright ©2003-2006 Tod Birdsall