Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
678 changes: 339 additions & 339 deletions 3rdParty/JCL/source/common/Jcl8087.pas

Large diffs are not rendered by default.

2,958 changes: 2,958 additions & 0 deletions 3rdParty/JCL/source/common/JclAbstractContainers.pas

Large diffs are not rendered by default.

4,331 changes: 4,331 additions & 0 deletions 3rdParty/JCL/source/common/JclAlgorithms.pas

Large diffs are not rendered by default.

8,542 changes: 4,271 additions & 4,271 deletions 3rdParty/JCL/source/common/JclAnsiStrings.pas

Large diffs are not rendered by default.

12,057 changes: 12,057 additions & 0 deletions 3rdParty/JCL/source/common/JclArrayLists.pas

Large diffs are not rendered by default.

2,388 changes: 2,388 additions & 0 deletions 3rdParty/JCL/source/common/JclArraySets.pas

Large diffs are not rendered by default.

1,293 changes: 650 additions & 643 deletions 3rdParty/JCL/source/common/JclBase.pas

Large diffs are not rendered by default.

21,387 changes: 21,387 additions & 0 deletions 3rdParty/JCL/source/common/JclBinaryTrees.pas

Large diffs are not rendered by default.

1,144 changes: 572 additions & 572 deletions 3rdParty/JCL/source/common/JclCharsets.pas

Large diffs are not rendered by default.

1,508 changes: 1,508 additions & 0 deletions 3rdParty/JCL/source/common/JclCompilerUtils.pas

Large diffs are not rendered by default.

1,584 changes: 1,584 additions & 0 deletions 3rdParty/JCL/source/common/JclComplex.pas

Large diffs are not rendered by default.

10,068 changes: 10,068 additions & 0 deletions 3rdParty/JCL/source/common/JclCompression.pas

Large diffs are not rendered by default.

4,941 changes: 4,941 additions & 0 deletions 3rdParty/JCL/source/common/JclContainerIntf.pas

Large diffs are not rendered by default.

251 changes: 251 additions & 0 deletions 3rdParty/JCL/source/common/JclCounter.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
{**************************************************************************************************}
{ }
{ Project JEDI Code Library (JCL) }
{ }
{ The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
{ you may not use this file except in compliance with the License. You may obtain a copy of the }
{ License at http://www.mozilla.org/MPL/ }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF }
{ ANY KIND, either express or implied. See the License for the specific language governing rights }
{ and limitations under the License. }
{ }
{ The Original Code is JclCounter.pas. }
{ }
{ The Initial Developers of the Original Code are Theo Bebekis and Marcel van Brakel. }
{ Portions created by Marcel van Brakel are Copyright (C) Marcel van Brakel. All Rights Reserved. }
{ Portions created by Theo Bebekis are Copyright (C) Theo Bebekis. All Rights Reserved. }
{ }
{ Contributor(s): }
{ Theo Bebekis }
{ Marcel van Brakel }
{ Robert Marquardt (marquardt) }
{ Matthias Thoma (mthoma) }
{ Petr Vones (pvones) }
{ }
{**************************************************************************************************}
{ }
{ This unit contains a high performance counter class which can be used for highly accurate timing }
{ }
{**************************************************************************************************}
{ }
{ Last modified: $Date:: $ }
{ Revision: $Rev:: $ }
{ Author: $Author:: $ }
{ }
{**************************************************************************************************}

unit JclCounter;

{$I jcl.inc}

interface

uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
{$IFDEF HAS_UNITSCOPE}
{$IFDEF MSWINDOWS}
Winapi.Windows,
{$ENDIF MSWINDOWS}
{$ELSE ~HAS_UNITSCOPE}
{$IFDEF MSWINDOWS}
Windows,
{$ENDIF MSWINDOWS}
{$ENDIF ~HAS_UNITSCOPE}
{$IFDEF HAS_UNIT_LIBC}
Libc,
{$ENDIF HAS_UNIT_LIBC}
JclBase;

type
TJclCounter = class(TObject)
private
FCounting: Boolean;
FElapsedTime: Float;
FOverhead: Int64;
FOverallElapsedTime: Float;
FFrequency: Int64;
FStart: Int64;
FStop: Int64;
{$IFDEF LINUX}
FTimeval: TTimeval;
{$ENDIF LINUX}
protected
function GetRunElapsedTime: Float;
public
constructor Create(const Compensate: Boolean = False);
procedure Continue;
procedure Start;
function Stop: Float;
property Counting: Boolean read FCounting;
property ElapsedTime: Float read FElapsedTime;
property Overhead: Int64 read FOverhead;
property RunElapsedTime: Float read GetRunElapsedTime;
end;

procedure ContinueCount(var Counter: TJclCounter);
procedure StartCount(var Counter: TJclCounter; const Compensate: Boolean = False);
function StopCount(var Counter: TJclCounter): Float;

type
EJclCounterError = class(EJclError);

{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$URL$';
Revision: '$Revision$';
Date: '$Date$';
LogPath: 'JCL\source\common';
Extra: '';
Data: nil
);
{$ENDIF UNITVERSIONING}

implementation

uses
{$IFDEF HAS_UNITSCOPE}
System.SysUtils,
{$ELSE ~HAS_UNITSCOPE}
SysUtils,
{$ENDIF ~HAS_UNITSCOPE}
JclResources;

procedure NoCounterError;
begin
raise EJclCounterError.CreateRes(@RsNoCounter);
end;

constructor TJclCounter.Create(const Compensate: Boolean);
const
Iterations: Integer = 10000;
var
Count: Integer;
TmpOverhead: Int64;
begin
inherited Create;

{$IFDEF MSWINDOWS}
if not QueryPerformanceFrequency(FFrequency) then
NoCounterError;
{$ENDIF MSWINDOWS}
{$IFDEF LINUX}
FFrequency := 100000; // 1 sec = 10E6 microseconds, therefore we have to divide by 10E5
{$ENDIF LINUX}

FCounting := False;
FOverhead := 0;

if Compensate then
begin
// Determine overhead associated with calling of the Start and Stop methods.
// This allows the Stop method to compensate for it and return a more
// accurate result. Thanks to John O'Harrow (john att elmcrest dott demon dott co dott uk)
TmpOverhead := 0;
for Count := 0 to Iterations-1 do
begin
Start;
Stop;
TmpOverhead := TmpOverhead + (FStop - FStart);
end;
FOverHead := Round(TmpOverhead / Iterations);
end;

FOverallElapsedTime := 0;
FElapsedTime := 0;
end;

procedure TJclCounter.Start;
begin
FCounting := True;
FElapsedTime := 0;
FOverallElapsedTime := 0;
{$IFDEF MSWINDOWS}
if not QueryPerformanceCounter(FStart) then
NoCounterError;
{$ENDIF MSWINDOWS}
{$IFDEF LINUX}
GetTimeOfDay(FTimeval, nil);
FStart := FTimeval.tv_sec * 100000 + (FTimeval.tv_usec);
{$ENDIF LINUX}
end;

function TJclCounter.Stop: Float;
begin
{$IFDEF MSWINDOWS}
if not QueryPerformanceCounter(FStop) then
NoCounterError;
{$ENDIF MSWINDOWS}
{$IFDEF LINUX}
GetTimeOfDay(FTimeval, nil);
FStop := FTimeval.tv_sec * 100000 + (FTimeval.tv_usec);
{$ENDIF LINUX}
FCounting := False;
FElapsedTime := FOverallElapsedTime + ((FStop - FStart - FOverhead) / FFrequency);
FOverallElapsedTime := FElapsedTime;
Result := FElapsedTime;
end;

function TJclCounter.GetRunElapsedTime: Float;
var
TimeNow: Int64;
begin
{$IFDEF MSWINDOWS}
TimeNow := 0;
if not QueryPerformanceCounter(TimeNow) then
NoCounterError;
{$ENDIF MSWINDOWS}
{$IFDEF LINUX}
GetTimeOfDay(FTimeval, nil);
TimeNow := FTimeval.tv_sec * 100000 + (FTimeval.tv_usec);
{$ENDIF LINUX}
Result := FOverallElapsedTime + ((TimeNow - FStart - FOverhead) / FFrequency);
end;

procedure TJclCounter.Continue;
var
Overall: Float;
begin
if not(FCounting) then
begin
Overall := FOverallElapsedTime;
Start;
FOverallElapsedTime := Overall;
end;
end;

procedure StartCount(var Counter: TJclCounter; const Compensate: Boolean = False);
begin
Counter := TJclCounter.Create(Compensate);
Counter.Start;
end;

function StopCount(var Counter: TJclCounter): Float;
begin
if Counter <> nil then
begin
Result := Counter.Stop;
FreeAndNil(Counter);
end
else
Result := 0.0;
end;

procedure ContinueCount(var Counter: TJclCounter);
begin
if Counter <> nil then
Counter.Continue;
end;

{$IFDEF UNITVERSIONING}
initialization
RegisterUnitVersion(HInstance, UnitVersioning);

finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}

end.
Loading