Unit mwfasttime;
Interface
Uses sysutils, windows, classes;
type TmwFastTime = class (TComponent) private c, n1, n2: TLargeInteger; function GetElapsedTime: ShortString; function GetElapsed: Extended; protected public constructor Create (AOwner: TComponent); override; destructor Destroy; override; Property Elapsed: Extended read GetElapsed; Property ELAPSEDTIME: ShortString Read GeeLapsedTime; Procedure Start; Published Property Name; Property Tag;
PROCEDURE register;
IMPLEMENTATION
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
Procedure Register; Begin RegisterComponents ('MW', [TMWFastTime]); END;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
Constructor TMWFastTime.create (Aowner: Tcomponent); Begin Inherited Create (Aowner); QueryperFormanceFrequency (C); END;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
DESTRUCTOR TMWFASTTIME.DESTROY; begin inherited destroy;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
function TmwFastTime.GetElapsed: Extended; begin {$ IFDEF VER120} Result: = (_LARGE_INTEGER (n2) .QuadPart - _LARGE_INTEGER (n1) .QuadPart) / _LARGE_INTEGER (c) .QuadPart; {$ ELSE} Result: = (n2.QuadPart - n1.quadpart) / c.quadpart; {$ ENDIF} end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
Function TMWFastTime.GetelapsedTime: shortstring; begin {$ IFDEF VER120} Result: = format ('seconds:% g', [getLetLapsed]); {$ else} result: = format ('seconds:% g', [getLetLapsed]) {$ ENDIF} end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
Procedure TMWFastTime.start; Begin QueryperFormanceCounter (N1); END;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
Procedure TMWFastTime.stop; Begin QueryperFormanceCounter (N2); END;
End.