计算程序的速度? [英] Calculating the speed of routines?
问题描述
要确定处理程序需要多长时间,例如函数程序,最好和最准确的方法是什么?
我问,因为我是目前正在尝试优化我的应用程序中的几个功能,当我测试这些更改时,很难通过查看它,如果有任何改进。所以如果我可以返回一个准确或接近准确的时间来处理一个例行程序,那么我会更清楚地了解如何对代码进行任何修改。
我考虑使用GetTickCount,但我不确定这是否接近准确?
有一个可重用的函数/过程来计算例程的时间,并使用它这样的东西:
//<准备计算代码
...
ExecuteSomeCode; //<代码测试
...
//<停止计算代码和处理
我期待收到一些建议。 >
谢谢。
Craig。
从我的知识,最准确的方法是使用 QueryPerformanceFrequency :
代码:
var
Freq,StartCount,StopCount:Int64;
TimingSeconds:real;
begin
QueryPerformanceFrequency(Freq);
QueryPerformanceCounter(StartCount);
//执行你想要的进程:...
QueryPerformanceCounter(StopCount);
TimingSeconds:=(StopCount - StartCount)/ Freq;
//显示时间:...
end;
What would be the best and most accurate way to determine how long it took to process a routine, such as a procedure of function?
I ask because I am currently trying to optimize a few functions in my Application, when i test the changes it is hard to determine just by looking at it if there was any improvements at all. So if I could return an accurate or near accurate time it took to process a routine, I then have a more clear idea of how well, if any changes to the code have been made.
I considered using GetTickCount, but I am unsure if this would be anything near accurate?
It would be useful to have a resuable function/procedure to calculate the time of a routine, and use it something like this:
// < prepare for calcuation of code
...
ExecuteSomeCode; // < code to test
...
// < stop calcuating code and return time it took to process
I look forward to hearing some suggestions.
Thanks.
Craig.
From my knowledge, the most accurate method is by using QueryPerformanceFrequency:
code:
var
Freq, StartCount, StopCount: Int64;
TimingSeconds: real;
begin
QueryPerformanceFrequency(Freq);
QueryPerformanceCounter(StartCount);
// Execute process that you want to time: ...
QueryPerformanceCounter(StopCount);
TimingSeconds := (StopCount - StartCount) / Freq;
// Display timing: ...
end;
这篇关于计算程序的速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!