What is the best way to measure how long code takes to execute?

后端 未结 10 1244
梦谈多话
梦谈多话 2020-12-08 04:04

I\'m trying to determine which approach to removing a string is the fastest.

I simply get the start and end time a

10条回答
  •  Happy的楠姐
    2020-12-08 04:40

    You can use the Stopwatch class.

    The Stopwatch measures elapsed time by counting timer ticks in the underlying timer mechanism. If the installed hardware and operating system support a high-resolution performance counter, then the Stopwatch class uses that counter to measure elapsed time.

    var sw = new Stopwatch();
    
    sw.Start();
    // ...
    sw.Stop();
    

提交回复
热议问题