When I downloaded the zip file and looked at your code, the problem became obvious: It is not the same code.
Since the two tests have different code, they are compiled differently by the C# compiler and optimized differently by the JIT compiler. Different registers are assigned to local variables. Different calling techniques are used. Different stack offsets are used.
Here are a few differences I noted between the two benchmark methods:
- They take different parameter types
- They contain different numbers (9 vs 7) and types of local variables
- They make different numbers of method calls
- They have a different number of loops
- One calls Application.DoEvents() and the other doesn't
My guess is that in your WinForms version of the code, the JIT compiler placed the variable 'i' at a stack offset whereas in the WPF version it placed it in a register, which then needed to be saved on each iteration.
In any case, don't blame the difference on WPF vs WinForms: Blame the difference on having two different tests that look superficially similar but got optimized differently.
Break the testing code out into a static method in a separate class. If you use identical code in both benchmarks I can pretty much guarantee you that you will get identical results.