当前位置:网站首页>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
边栏推荐
猜你喜欢
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
Online sql to excel (xls/xlsx) tool
西门子HMI下载时提示缺少面板映像解决方案
Master the use of auto analyze in data warehouse
Hough Transform 霍夫变换原理
92. (cesium chapter) cesium building layering
FPGA时序约束分享01_四大步骤简述
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
Stream流
MySQL数据库基本操作-DDL | 黑马程序员
随机推荐
Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
Euler function
Shell 编程核心技术《二》
多表操作-外连接查询
ftp、sftp文件传输
基于NCF的多模块协同实例
HDU 1097 A hard puzzle
Reflection (I)
BCG 使用之新建向导效果
Shell 編程核心技術《四》
Shell programming core technology "four"
安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
Wechat reading notes of "work, consumerism and the new poor"
876. Intermediate node of linked list
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
English grammar_ Noun - use
Introduction to polyfit software
Online data migration scheme encountered in the project 1 - general idea sorting and technical sorting
PolyFit软件介绍
OpenCV的二值化处理函数threshold()详解