operation time of method
how to know, how much time take method in C# for example, i have label1 and method
public int MakeSome(int a, int b)
{
for (int i = 0; i < a; i++)
{
for (开发者_开发技巧int j = 0; j < b; j++)
{
// some operation
}
}
return returnIntValue;
}
know, how to know how many milliseconds take MakeSome method, and write value in label1. thanks
You can use the Stopwatch
class:
Stopwatch st = new Stopwatch();
st.Start();
// call MakeSome method...
st.Stop();
Then you can check the st.ElapsedMilliseconds
property.
Use the Stopwatch class from the System.Diagnostics namespace.
Create a time variable and assign the DateTime.Now to it then subtract the two times.
(Use the Stopwatch class instead - it is more elegant)
精彩评论