在类中添加
[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);
添加方法
{
long count = 0;
long count1 = 0;
long freq = 0;
double result = 0;
QueryPerformanceFrequency(ref freq);
QueryPerformanceCounter(ref count);
#region //需要测试的模块
int heisetoufa;
for (heisetoufa = 1; heisetoufa < 10000; heisetoufa++)
{
if (heisetoufa == 5000)
{
Thread.Sleep(1000);
}
}
#endregion //需要测试的模块
QueryPerformanceCounter(ref count1);
count = count1 - count;
result = (double)(count) / (double)freq;
label1.Text = result.ToString();
label1.Refresh();
}