By now you would have no doubt heard about the new dynamic type in C# 4 and how it has changed the way you write interop code in C#. As impressed as I am by it, I have been wondering just how much (if any) of a performance hit we’d have to pay to move away from the fast but strict type system we have had so far.
Since the very first release of the .Net framework we’ve had the ability to invoke a method dynamically using reflection, but this is SLOW, so what of the new dynamic type? With this in mind, I put together a quick test to see how the three ways of invoking a method differ in performance:
static void Main(string args)
const int maxAttempt = 1000000;
var stopwatch = new Stopwatch();
#region Normal Invocation
var prog = new Program();
for (int i = 0; i