日期:2014-05-18 浏览次数:20913 次
class Program { static Process process = Process.GetCurrentProcess(); static PerformanceCounter privateBytesCounter = new PerformanceCounter("Process", "Private Bytes", process.ProcessName); static PerformanceCounter workingSetCounter = new PerformanceCounter("Process", "Working Set", process.ProcessName); static void Main(string[] args) { GetMeasure(); Console.WriteLine("按下回车申请大内存"); Console.ReadLine(); int[] arr = new int[10000000]; for (int i = 0; i < arr.Length; i++) { arr[i] = i; } GetMeasure(); privateBytesCounter.Dispose(); workingSetCounter.Dispose(); Console.ReadKey(); } private static void GetMeasure() { Console.WriteLine("{0,30} {1,20}", "Private bytes", "working set"); Console.WriteLine("process数据{0,15} {1,20}", process.PrivateMemorySize64 / 1024, process.WorkingSet64 / 1024); Console.WriteLine("性能计数器数据{0,12} {1,20}", privateBytesCounter.NextValue() / 1024, workingSetCounter.NextValue() / 1024); }