C# Calculate program time

Method 1: stopwatch

using System.Diagnostics;
public class Test
{
	static void Main(string[] args)
	{
		Stopwatch swt = new Stopwatch();
		swt.Start();
		Thread.Sleep(999);
		swt.Stop();
		Console.WriteLine("程序耗时为:"+swt.ElapsedMilliseconds +"ms");
		Console.ReadKey();
	}
}

Method 2: DateTime.Now

using System;
public class Test
{
	static void Main(string[] args)
	{
		var start = DateTime.Now;
		Thread.Sleep(999);
		var stop = DateTime.Now;
		Console.WriteLine("程序耗时为:"+(stop - start).TotalMilliseconds+"ms");
		Console.ReadKey();		
	}
}

Guess you like

Origin blog.csdn.net/a497785609/article/details/132275066