Google tag

Pages

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

Collection of Free or Open Source Software (Updated 06-Apr-2023)

Windows Installation Customizer
1. nLite
2. vLite

SVN Server

1. VisualSVN Server

Web Based Scada
1. MBLogic

Mind Mapping 
1. Freeplane 
1. Free Mind 

3D Rendering
1. Blender 

Image Viewer
1. FastStone Viewer 

Screen Capture
1. FastStone Capture 
2. GreenShot 
3. PicPick 

Screen Cast Tools
1. CamStudio 
2. Licecap 428KB (GIF Animate) 
3. GIFCam 686KB Version 4.5 

Disk Management
1. TreeSize Free 

PDF Maker
1. CutePDF + Converter 

Steal in other words


Shop lift, give finger discount, swipe

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;