using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { start: Console.Write("实例调用耗时:"); Test(() => { for (int i = 0; i < 10; i++) { new A().Test(); } }); Console.Write("静态调用耗时:"); Test(() => { for (int i = 0; i < 10; i++) { B.Test(); } }); Console.WriteLine(); Console.ReadKey(); goto start; } static void Test(Action action) { double f = 0; for (int j = 0; j < 20; j++) { DateTime dt = DateTime.Now; System.Diagnostics.Stopwatch stop = new System.Diagnostics.Stopwatch(); stop.Start(); for (int i = 0; i < 1000000; i++) action(); stop.Stop(); TimeSpan time = stop.Elapsed; f += time.TotalMilliseconds; } Console.WriteLine(f / 20); } } class A { public void Test() { } } class B { public static void Test() { } }