unit Chronometer;
(* ***** BEGIN LICENSE BLOCK *****
* Copyright (C) 2004 Durand Emmanuel
* Copyright (C) 2004 Burgel Eric
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact :
* filters@edurand.com
* filters@burgel.com
*
* ***** END LICENSE BLOCK ***** *)
{
edurand (filters@edurand.com)
eburgel (filters@burgel.com)
}
interface
uses
Windows, Math;
type
TChronometer = class
public
constructor Create;
procedure Start;
function Stop : Integer;
function getTime() : int64;
private
counterStart,counterStop,freq : int64;
t : Extended;
end;
implementation
constructor TChronometer.Create;
begin
QueryPerformanceFrequency(freq);
t:=0;
end;
procedure TChronometer.Start;
begin
QueryPerformanceCounter(counterStart);
end;
function TChronometer.Stop : Integer;
var
countTime : Integer;
begin
QueryPerformanceCounter(counterStop);
countTime:=counterStop-counterStart;
t:=countTime / freq*1000;
Result:=Floor(t);
end;
function TChronometer.getTime() : int64;
begin
Result:=Floor(t);
end;
end.