当前位置:网站首页>C # use stopwatch to measure the running time of the program
C # use stopwatch to measure the running time of the program
2022-07-04 19:38:00 【Robot automation control】
Stopwatch Examples can be measured ⼀ Run at intervals ⾏ Time , It can also measure the total operation of multiple time intervals ⾏ Time . In a typical Stopwatch ⽅ In the case , First tune ⽤ Start ()⽅ Law , Then tune up ⽤ Stop() ⽅ Law , Finally make ⽤ Elapsed Attribute check operation ⾏ Time .
TimeSpan The value can be expressed as [-]d.hh:mm:ss.ff, Where the minus sign is optional , It indicates a negative time interval ,d The component represents days ,hh For hours (24 hourly ),mm Represents minutes ,ss For seconds , and ff Is the fractional part of the second . namely , The time interval includes positive and negative days of the whole 、 Number of days and remaining less than one day , Or less than a day .
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
namespace Stopwatch Use
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// Object instantiation
Stopwatch stopwatch = new Stopwatch();
private void button1_Click(object sender, EventArgs e)
{
// The timer starts
stopwatch.Start();
for(int i = 0; i < 800000000;i++)
{
int j = 0;
j = j + 2;
}
// The timer stops
stopwatch.Stop();
// Determine whether the timing is in progress ,true For in progress
bool isrunning = stopwatch.IsRunning;
// Get run time millisecond
long times1 = stopwatch.ElapsedMilliseconds;
TimeSpan times2 = stopwatch.Elapsed;
double days = times2.TotalDays;
double hours = times2.TotalHours;
double minutes = times2.TotalMinutes;
double seconds = times2.TotalSeconds;
double milliseconds = times2.TotalMilliseconds;
textBox1.Text += " Total operation time :" + times1 + " millisecond ";
textBox2.Text += " Total operation time :" + hours + " Hours ";
textBox3.Text += " Total operation time :" + minutes + " branch ";
textBox4.Text += " Total operation time :" + seconds + " second ";
textBox5.Text += " Total operation time :" + milliseconds + " millisecond ";
}
}
}
As can be seen from the above figure TimeSpan Timing time ratio StopWatch More accurate
边栏推荐
- 项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
- Matrix flip (array simulation)
- How to use async Awati asynchronous task processing instead of backgroundworker?
- 测试工程师如何“攻城”(下)
- . Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
- An example of multi module collaboration based on NCF
- Wechat reading notes of "work, consumerism and the new poor"
- “只跑一趟”,小区装维任务主动推荐探索
- Technologie de base de la programmation Shell IV
- Some thoughts on whether the judgment point is located in the contour
猜你喜欢

Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading

How to use async Awati asynchronous task processing instead of backgroundworker?

FPGA timing constraint sharing 01_ Brief description of the four steps

用实际例子详细探究OpenCV的轮廓绘制函数drawContours()

如何使用Async-Awati异步任务处理代替BackgroundWorker?

Hough Transform 霍夫变换原理

The 300th weekly match of leetcode (20220703)

在线SQL转Excel(xls/xlsx)工具

Master the use of auto analyze in data warehouse

PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
随机推荐
1002. A+B for Polynomials (25)(PAT甲级)
Cbcgpprogressdlg progress bar used by BCG
YOLOv5s-ShuffleNetV2
Opencv functions and methods related to binary threshold processing are summarized for comparison and use
Reflection (I)
Niuke Xiaobai monthly race 7 I new Microsoft Office Word document
The kth largest element in the array
1008 elevator (20 points) (PAT class a)
Euler function
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
欧拉函数
项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
1005 spell it right (20 points) (pat a)
Online text line fixed length fill tool
Pytest 可视化测试报告之 Allure
FPGA timing constraint sharing 01_ Brief description of the four steps
Matrix flip (array simulation)
Pytorch学习(四)
Some thoughts on whether the judgment point is located in the contour
黑马程序员-软件测试--08阶段2-linux和数据库-23-30-进程端口相关,修改文件权限,端口号信息的获取,程序和进程相关操作,linux命令案例