运行一下就知道时间cost在哪了。
public static void test() { DateTime t1 = DateTime.Now; PerformanceCounter cpuCounter = new PerformanceCounter(); cpuCounter.CategoryName = "Processor"; cpuCounter.CounterName = "% Processor Time"; cpuCounter.InstanceName = "_Total"; cpuCounter.MachineName = "."; String s2 = cpuCounter.NextValue().ToString(); DateTime t2 = DateTime.Now; Console.Out.WriteLine((t2 - t1).TotalSeconds); //DateTime d1 = new DateTime(2004, 1, 1, 15, 36, 05); //DateTime d2 = new DateTime(2004, 1, 1, 15, 37, 35); String s = cpuCounter.NextValue().ToString(); DateTime t3 = DateTime.Now; Console.Out.WriteLine((t3 - t2).TotalSeconds); WebRequest request = WebRequest.Create("http://baidu.com"); request.GetResponse(); DateTime t4 = DateTime.Now; //TimeSpan d3 = d2.Subtract(d1); Console.Out.WriteLine((t4 - t3).TotalSeconds); Thread.Sleep(10000); }