Wednesday, September 8, 2010

About Optimization from David


Original link: forum/topics/learning-vbnet-and-rhinocommon

optimization comes in multiple flavours. Macro-Optimization is difficult but generally yields good results, especially if you're implementing proven algorithms (binary search vs. linear search for example). Micro-Optimization rarely makes a big difference, especially when you're using 'smart' compilers like modern C++ or .NET ones. In fact, it's not that rare that an attempt at micro-optimization is actually detrimental, as the compiler suddenly no longer 'understands' what it is you're doing and can no longer help out.

Two things I've learned over the years about optimization:

1. You will not be able to guess/deduce which parts of your code are bottlenecks. Don't start blindly optimizing code.

Always always always profile your code first

. You can either build in custom profilers (the .NET framework supplies some useful classes for this) or use an external profiler (I use RedGate Ants).

2. Debugging code is twice as hard as writing code. Therefore, writing complicated optimizations that stretch your skills to the limit is pointless and frustrating. You will not be able to debug your optimized code and end up worse off than when you started.

No comments:

Post a Comment