Measure execution time in C#

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

    It's not just that StopWatch is more accurate, but also that DateTime.Now will give incorrect results in some circumstances.

    Consider what happens during a daylight saving time switch-over, for example — using DateTime.Now can actually give a negative answer!

提交回复
热议问题