Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

operation time of method

Tags:

c#

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

like image 857
loviji Avatar asked Nov 28 '22 19:11

loviji


1 Answers

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.

like image 192
Christian C. Salvadó Avatar answered Nov 30 '22 09:11

Christian C. Salvadó