Measure execution time in C#

前端 未结 8 617
广开言路
广开言路 2020-12-13 18:12

I want to measure the execution of a piece of code and I\'m wondering what the best method to do this is?

Option 1:

DateTime StartTime = DateTime.Now         


        
8条回答
  •  既然无缘
    2020-12-13 18:53

    Use below code

    DateTime dExecutionTime;
    dExecutionTime = DateTime.Now;
          TimeSpan span = DateTime.Now.Subtract(dExecutionTime);
                      lblExecutinTime.Text = "total time taken " +   Math.Round(span.TotalMinutes,2) + " minutes .   >>---> " + DateTime.Now.ToShortTimeString();
    

提交回复
热议问题