C# high precision timing

background

The company took over the real-time detection task, and colleagues wrote and trained the model, and configured the test to calculate the time required for a picture

plan

In the past, DateTime.Now was used to pinch points at both ends, which is very unprofessional.

Now use the StopWatch class in the System.Diagnostics namespace to implement

the code

using System.Diagnostics;

//实例化计时对象
StopWatch sw=new StopWatch();

//开启计时
sw.Start();

//编写业务代码
do your task

//结束计时
sw.Stop();

//获取业务代码执行的用时,单位是秒[s]
float times=((float)sw.ElapsedTicks)/Stopwatch.Frequency;

Guess you like

Origin blog.csdn.net/qq_36694133/article/details/130573718
Recommended