开发者

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜