确定处理例程所需的时间(例如函数的过程)最好和最准确的方法是什么?
我问,因为我目前正在尝试优化我的应用程序中的一些函数,当我测试更改时,如果有任何改进,只需通过查看就很难确定.因此,如果我能够返回一个准确或接近准确的处理例程的时间,那么我可以更清楚地了解代码是否有任何变化.
我考虑过使用GetTickCount,但我不确定这是否接近准确?
有一个可恢复的函数/过程来计算例程的时间是有用的,并使用它像这样:
// < prepare for calcuation of code
...
ExecuteSomeCode; // < code to test
...
// < stop calcuating code and return time it took to process
Run Code Online (Sandbox Code Playgroud)
我期待听到一些建议.
谢谢.
克雷格.
我在Delphi7中寻找一个以毫秒或纳秒为单位的计时器.我必须通过顺序搜索检查三个ISAM文件的速度.第一个ind文件包含50个字符串,如"record_0"到"record_50".第二个 - "record_0"到"record_500",第三个 - "record_0"到"record_5000".我实现了一切,但我不知道如何制作计时器.我正在比较一个字符串与每个ISAM文件中的最后一项.这是我的第一个ind文件的代码:
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
var content : String[20];
var indexCounter:integer;
var keyword:string;
begin
//First ISAM file
AssignFile(indF1, 'index1.ind');
ReWrite(indF1);
Reset(indF1);
for i:=0 to 49 do begin
content := 'record_';
content := content + IntToStr(i+1);
index1.index1 := content;
index1.position1 := FileSize(indF1);
Seek(indF1, FileSize(indF1));
write(indF1, index1);
end;
CloseFile(indF1);
Label12.Caption := FileSizeStr('index1.ind');
//Sequential search in first ind file
Reset(indF1);
keyword := 'record_50';
indexCounter := 0;
//start timer
while not Eof(indF1) do begin
Seek(indF1, indexCounter);
Read(indF1, Index1);
if …Run Code Online (Sandbox Code Playgroud) 我使用delphi语言,我需要以微秒计算进程的时间.
我可以用小时秒和毫秒来计算时间,在delphi语言中是否有以微秒为单位的计算时间函数?
delphi ×3
gettickcount ×1
milliseconds ×1
optimization ×1
performance ×1
timer ×1
while-loop ×1