当前位置:网站首页>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
边栏推荐
猜你喜欢
Detailed explanation of the binary processing function threshold() of opencv
Online text line fixed length fill tool
Master the use of auto analyze in data warehouse
mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
Euler function
Swagger突然发癫
Oracle with as ora-00903: invalid table name multi report error
JVM系列之对象的创建
如何使用Async-Awati异步任务处理代替BackgroundWorker?
随机推荐
Socket programming demo II
Introduction to polyfit software
Mysql database basic operation -ddl | dark horse programmer
Personal thoughts on Architecture Design (this article will be revised and updated continuously later)
一文掌握数仓中auto analyze的使用
LM10丨余弦波动顺势网格策略
[QNX Hypervisor 2.2用户手册]6.3.1 工厂页和控制页
“只跑一趟”,小区装维任务主动推荐探索
TCP两次挥手,你见过吗?那四次握手呢?
MySQL数据库基本操作-DDL | 黑马程序员
Unity editor extends C to traverse all pictures in folders and subdirectories
Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
92. (cesium chapter) cesium building layering
How test engineers "attack the city" (Part 2)
黑马程序员-软件测试--07阶段2-linux和数据库-09-24-linux命令学习步骤,通配符,绝对路径,相对路径,文件和目录常用命令,文件内容相关操作,查看日志文件,ping命令使用,
HDU 6440 2018 Chinese college student program design network competition
测试工程师如何“攻城”(下)
1008 elevator (20 points) (PAT class a)
QT realizes interface sliding switching effect