当前位置:网站首页>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
边栏推荐
- Jetpack compose tutorial
- Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
- Euler function
- Shell programming core technology "three"
- Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
- . Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
- kotlin 基本数据类型
- Introduction to polyfit software
- YOLOv5s-ShuffleNetV2
- Personal thoughts on Architecture Design (this article will be revised and updated continuously later)
猜你喜欢
如何使用Async-Awati异步任务处理代替BackgroundWorker?
abc229 总结(区间最长连续字符 图的联通分量计数)
Online text line fixed length fill tool
多表操作-内连接查询
用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
92.(cesium篇)cesium楼栋分层
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
MySQL数据库基本操作-DDL | 黑马程序员
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
黑马程序员-软件测试--09阶段2-linux和数据库-31-43修改文件权限字母发的说明,-查找链接修改文件,查找文件命令,链接文件,压缩解压方式,vi编辑器基本使用,
随机推荐
西门子HMI下载时提示缺少面板映像解决方案
Allure of pytest visual test report
Pythagorean number law (any three numbers can meet the conditions of Pythagorean theorem)
1002. A+B for Polynomials (25)(PAT甲级)
Add namespace declaration
Lm10 cosine wave homeopathic grid strategy
用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
Educational Codeforces Round 22 E. Army Creation
LM10丨余弦波动顺势网格策略
Introduction to polyfit software
Hough Transform 霍夫变换原理
abc229 总结(区间最长连续字符 图的联通分量计数)
安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
黑马程序员-软件测试--09阶段2-linux和数据库-31-43修改文件权限字母发的说明,-查找链接修改文件,查找文件命令,链接文件,压缩解压方式,vi编辑器基本使用,
English语法_名词 - 使用
Online data migration scheme encountered in the project 1 - general idea sorting and technical sorting
Shell 编程核心技术《一》
函数式接口
876. Intermediate node of linked list
Pytorch学习(四)