花费的时间正在运行的程序 [英] Time spend running program

查看:81
本文介绍了花费的时间正在运行的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个文本框或在输出时如何打印程序花费运行?

How I print in a textbox or at the output the time that the program spend running?

我希望它显示为一个for循环,才能得到多少时间需要在每个for循环

I want it to be displayed into a for-loop, to get how much time needs each for-loop .

推荐答案

您可以尝试:

DateTime dt = DateTime.Now;
for (.......)
{
}
TimeSpan ts = DateTime.Now - dt;
textbox1.Text = ts.TotalMilliseconds.ToString();

或(根据的 MSDN )如果你需要更好的分辨率

or (according to MSDN) if you need better resolution

Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
for (.......)
{
}
stopWatch.Stop();
textbox1.Text = stopWatch.ElapsedMilliseconds.ToString();

这篇关于花费的时间正在运行的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆