using System;
using System.Diagnostics;
class Program
{
static void Main()
{
// 创建 Stopwatch 对象并开始计时
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
// 在这里写入需要计时的代码
for (int i = 0; i < 1000000; i++)
{
Console.WriteLine(i);
}
// 结束计时并获取经过的时间
stopwatch.Stop();
TimeSpan elapsedTime = stopwatch.Elapsed;
// 输出执行时间(单位为毫秒)
Console.WriteLine("代码执行时间:" + elapsedTime.TotalMilliseconds + " 毫秒");
}
}
C# 代码执行时间
最新推荐文章于 2024-04-16 19:30:35 发布