C#计算运行时间

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.Remoting.Messaging;
using System.Text;

namespace ConsoleApplication1
{
    static class Program
    {

        static void Main(string[] args)
        {
            int timeS = System.Environment.TickCount;
            int timeE = System.Environment.TickCount;
            var timeSpan = new Stopwatch();
            timeSpan.Start();
            Excute(() => { Console.WriteLine("test"); });
            timeSpan.Stop();
            Console.WriteLine(timeSpan.ElapsedMilliseconds);
            Console.ReadKey();
        }

        public static void Excute(Action code)
        {
            code();
        }
    }
}

你可能感兴趣的:(C#计算运行时间)