How long does my code take to run?

后端 未结 6 1529
轮回少年
轮回少年 2021-02-05 22:43

How can I find out how much time my C# code takes to run?

6条回答
  •  独厮守ぢ
    2021-02-05 23:16

    Check out the Stopwatch class:

    Stopwatch sw = new Stopwatch();
    sw.Start();
    
    // your code here
    
    sw.Stop();
    TimeSpan elapsedTime = sw.Elapsed;
    

提交回复
热议问题