[DllImport("Kernel32.dll")]
public static extern bool QueryPerformanceCounter(out long value);
[DllImport("Kernel32.dll")]
public static extern bool QueryPerformanceFrequency(out long value);
/* */////////////////////////////////////
private void button1_Click_1(object sender, System.EventArgs e)
...{
long counter_s = 0,counter_e = 0, freq = 0;
QueryPerformanceCounter(out counter_s);
QueryPerformanceCounter(out counter_e);
QueryPerformanceFrequency(out freq);
MessageBox.Show(string.Format("{0:.#######}",(counter_e - counter_s) / freq));
MessageBox.Show(freq.ToString());
}
本文介绍如何利用 C# 中的 DllImport 特性调用 Kernel32.dll 的 QueryPerformanceCounter 和 QueryPerformanceFrequency 函数来测量程序运行时间,并通过示例代码展示如何计算并显示两次计数之间的频率比。
2万+

被折叠的 条评论
为什么被折叠?



