public class Performance
{
public delegate void CalculateHanlder();
public static void CalculateMethod(CalculateHanlder method)
{
Stopwatch st = new Stopwatch();
st.Start();
method.Invoke();
st.Stop();
string msg = string.Format("Elapsed = {0} in [{1}]", st.Elapsed.ToString(), method.Method.ToString());
Console.WriteLine(msg);
Debug.WriteLine(msg);
}
}
bool Test(int x1, int x2, int x3, int x4, int x5)
{
if( (x1 == x2) && (x2 == x3) && (x3 == x4) && (x4 == x5) ) return true;
else
return false;
}
bool Test2(int x1, int x2, int x3, int x4, int x5)
{
if( x == x2)
{
if( x2 == x3)
if(x3 == x4)
if(x4 == x5)
return true;
}
else
return false;
}
void TestIf()
{
for(int i = 0 ; i < 100000; i ++)
Test(1,2,3,4,5);
}
Performance.CalculateMethod(TestIf);
You can use these code to test.
Using
StopWatch
can count the executing time.
This is my library function, you can pass a none parameter function to tick.