关闭。这个问题需要details or clarity .它目前不接受答案。
想改进这个问题?通过 editing this post 添加详细信息并澄清问题.
8年前关闭。
Improve this question
我在 c# 中搜索计算循环持续时间的方法或任何类似的东西,认为我的程序包含 for 或 while “for(...,...,...){}
” 我需要方法输出的类型需要多少时间
最佳答案
Provides a set of methods and properties that you can use to accurately measure elapsed time.
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
// stuff you want to time here...
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("RunTime " + elapsedTime);
The Stopwatch measures elapsed time by counting timer ticks in the underlying timer mechanism. If the installed hardware and operating system support a high-resolution performance counter, then the Stopwatch class uses that counter to measure elapsed time. Otherwise, the Stopwatch class uses the system timer to measure elapsed time. Use the Frequency and IsHighResolution fields to determine the precision and resolution of the Stopwatch timing implementation.
关于c# - 如何知道c#中的循环持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18427160/