Measure execution time in C#

前端 未结 8 631
广开言路
广开言路 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:45

    I generally use StopWatch for this kind of situation.

    From MSDN page:

    StopWatch

    Provides a set of methods and properties that you can use to accurately measure elapsed time.

    In the following post I use it to compare the execution time of LINQ vs PLINQ:

    Parallel LINQ (PLINQ) with Visual Studio 2010

提交回复
热议问题