I\'ve written two equivalent methods:
static bool F(T a, T b) where T : class
{
return a == b;
}
static bool F2(A a, A b)
{
return a == b;
I think it's the answer for my question, but what magic can I use to deny boxing?
If your goal is only to compare, you can do this:
public class A : IEquatable {
public bool Equals( A other ) { return this == other; }
}
static bool F( IEquatable a, IEquatable b ) where T : IEquatable {
return a==b;
}
This will avoid the boxing.
As for the major timing deviation, I think everyone already established there was a problem with how you set up the stopwatch. I use a different technique where if I want to remove the loop itself from the time result, I take an empty baseline and just subtract that from the difference of time. It's not perfect, but it produces a fair result and doesn't slow from starting and stopping the timer over and over.