Delphi Implement a microsecond resolution Delay
Implement a microsecond resolution Delay?
Author: Lemy
Homepage: http://www.swissdelphicenter.com
// Wait 0.2ms
procedure PerformanceDelay;
Delphi function / procedure execution time before and after
.................................................. .........
Question/Problem/Abstract:
I am optimizing a function and want to know the difference in execution time before and after optimization in microseconds!!
Answer:
put this in the var section of your function or procedure
Ctr1, Ctr2, Freq,Overhead: int64;
R: extended;
and put this at the beginnig of the function or more generally speaking at the beginning of the code you want to optimize.
[DELPHI] QueryPerformanceFrequency(Freq);
QueryPerformanceCounter(Ctr1);
QueryPerformanceCounter(Ctr2);
Overhead := Ctr2 - Ctr1; // determine API overhead
QueryPerformanceCounter(Ctr1);
put this at the end of the code
QueryPerformanceCounter(Ctr2);
R := ((Ctr2 - Ctr1) - Overhead) / Freq;
showmessage( 'The function took ' + FloatToStr(R) + ' seconds'); [/DELPHI]
important note: remember that the execution time of any function under most operating systems is affected also by services and programs running in the backgroud. So it is adviced that you keep your desktop state constant while optimizing.
This way you will get execution time in microsecond precision.
This is translated to delphi from a vb article at MSDN.
//This is the end of the article.
.................................................. .........
http://www.swissdelphicenter.ch/en/showcode.php?id=498
Question/Problem/Abstract:
I am optimizing a function and want to know the difference in execution time before and after optimization in microseconds!!
Answer:
put this in the var section of your function or procedure
Ctr1, Ctr2, Freq,Overhead: int64;
R: extended;
and put this at the beginnig of the function or more generally speaking at the beginning of the code you want to optimize.
[DELPHI] QueryPerformanceFrequency(Freq);
QueryPerformanceCounter(Ctr1);
QueryPerformanceCounter(Ctr2);
Overhead := Ctr2 - Ctr1; // determine API overhead
QueryPerformanceCounter(Ctr1);
put this at the end of the code
QueryPerformanceCounter(Ctr2);
R := ((Ctr2 - Ctr1) - Overhead) / Freq;
showmessage( 'The function took ' + FloatToStr(R) + ' seconds'); [/DELPHI]
important note: remember that the execution time of any function under most operating systems is affected also by services and programs running in the backgroud. So it is adviced that you keep your desktop state constant while optimizing.
This way you will get execution time in microsecond precision.
This is translated to delphi from a vb article at MSDN.
//This is the end of the article.
.................................................. .........
http://www.swissdelphicenter.ch/en/showcode.php?id=498
Collection of Free or Open Source Software (Updated 06-Apr-2023)
Delphi7实现MD5
delphi7里带了标准的MD5算法,单元文件IdHashMessageDigest.pas
例子:
uses
IdHashMessageDigest;//MD5计算
function MD5(CheckStr:string):String; //CheckStr为待加密的文件路路径。
var
MyMD5: TIdHashMessageDigest5;
begin
MyMD5:=TIdHashMessageDigest5.Create;
Result:=MyMD5.AsHex(MyMD5.HashValue(TFileStream.Create(CheckStr,fmOpenRead or fmSharedenyNone)));
MyMD5.Free;
end;
Subscribe to:
Posts (Atom)