Thursday, December 16, 2004
Tidbits from Microsoft Performance Guide
I just had a read through parts of the Microsoft "Improving .NET Performance and Scalability" guide (microsoft.com/perf), and learned some interesting new things:
- you can use a finally block without a catch block - this ensures that code is run regardless of whether an exception is raised, and doesn't carry the performance penalties of using catch
- marking derived class methods as "sealed" can improve performance, since the compiler can inline the method call - virtual methods cannot be inlined
- for performs better than foreach because of the overhead and potential boxing caused by the enumerators used by foreach - this doesn't mean you shouldn't use foreach, but where performance is paramount, for is faster
- to perform a case-insensitive string comparison, the String static member Compare is faster than casting strings to lower or upper case