gpt4 book ai didi

c# - 如何计算c#应用程序的执行时间

转载 作者:太空狗 更新时间:2023-10-30 00:01:51 25 4
gpt4 key购买 nike

如何计算 C# 应用程序的执行时间。我有一个 c# windows 应用程序,我需要在其中计算执行时间,但我不知道我必须在哪里进行。谁能帮帮我?

最佳答案

使用 System.Diagnostics 的秒表

static void Main(string[] args)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
Thread.Sleep(10000);
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);
}

关于c# - 如何计算c#应用程序的执行时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9954571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com