C#测试代码效率的方法using System; using System.Threading; class Dachie { [System.Runtime.InteropServices.DllImport("Kernel32.dll")] static extern bool QueryPerformanceCounter(ref long count); [System.Runtime.InteropServices.DllImport("Kernel32.dll")] static extern bool QueryPerformanceFrequency(ref long count); [STAThread] static void Main(string[] args) { long count = 0; long count1 = 0; long freq = 0; double result = 0; QueryPerformanceFrequency(ref freq); QueryPerformanceCounter(ref count); #region 放入逻辑代码 #endregion QueryPerformanceCounter(ref count1); count = count1 - count; result = (double)(count) / (double)freq; Console.WriteLine("耗时: {0} 秒", result); Console.ReadLine(); } }
c# 计算程序执行时间
C#测试代码效率的方法
作者:达奇
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。