1
0
mirror of https://github.com/loginov-dmitry/multithread.git synced 2025-07-17 19:17:54 +02:00

Для корректного отображения в github пришлось заменить русские комментарии на английские

This commit is contained in:
loginov-dmitry
2020-06-29 00:19:38 +03:00
parent 21fe72b316
commit 28f14e3a03

View File

@ -31,50 +31,50 @@ uses
Windows, SysUtils, Classes, Contnrs, SyncObjs, DateUtils, StrUtils, Math;
type
{ TPerformance ������������� ��� ������� ������ �������,
���������� ����� ������ ���������.
��������! ��������� � �������������
����������� � ������������ � ��������� ����������� (�������� ��
������������� ���������� PerformanceIgnoredTicks }
{ TPerformance is designed to accurately measure time,
passed after the start of measurement.
Attention! Microsecond measurements
performed with an error of several microseconds (despite
using the variable PerformanceIgnoredTicks }
TPerformance = record
private
FStartCounter: Int64;
FIsRunning: Boolean;
FElapsedTicks: Int64;
public
// �������� �����.
// Starts measuring
procedure Start;
// ��������� �����. ��������� ���� FElapsedTicks. ����� ����, ��� ������
// ����� Stop, ������ ElapsedXXX ����� ���������� ����������� � FElapsedTicks ��������
// Finishes measuring. Updates the FElapsedTicks field. After the Stop method
// is called, the ElapsedXXX methods will return the value stored in FElapsedTicks
procedure Stop;
// ���������� ���-�� ����������� ����� ������ �������
// Returns the number of milliseconds after the start of measurement
function ElapsedMilliseconds(AStartNew: Boolean = False): Int64;
// ���������� ���-�� ����������� ����� ������ �������
// Returns the number of microseconds after the start of measurements
function ElapsedMicroseconds(AStartNew: Boolean = False): Int64;
// ���������� ���-�� ������ ����� ������ �������
// Returns the number of seconds after the start of measurement
function ElapsedSeconds(AStartNew: Boolean = False): Double;
// ���������� ���������� ����� � ������ �������
// Returns the number of ticks from the beginning of measurements
function ElapsedTicks(AStartNew: Boolean = False): Int64;
// ���������� ����� (TDateTime), ��������� � ������ �������
// Returns the time (TDateTime) elapsed since the start of measurement
function ElapsedTime(AStartNew: Boolean = False): TDateTime;
// ���������� True, ���� ��������� ��������
// Returns True if measurements are running.
property IsRunning: Boolean read FIsRunning;
end;
TPerformanceEvent = record
// ����/����� ������ � ��������� ������� (�� ������������ ���������� �������)
// Date / time of the beginning and end of the event (according to the standard system timer)
BegDateTime: TDateTime;
EndDateTime: TDateTime;
EventName: string; // ������������ �������
BegCounter: Int64; // �������� �������� � ������ �������
EndCounter: Int64; // �������� �������� � ����� �������
EventName: string; // Event name
BegCounter: Int64; // Counter value at the beginning of the event
EndCounter: Int64; // Counter value at the end of the event
function ElapsedTicks: Int64;
function ElapsedMilliseconds: Int64;
@ -88,26 +88,25 @@ type
eoWriteBegTime, eoWriteEndTime, eoUseMicroSec, eoWriteFromStart);
TGetPerformanceEventsOptions = set of TGetPerformanceEventsOption;
{���������-������ ��� ���������������� ������������ �������}
// TPerformanceEvents - record for event duration logging
TPerformanceEvents = record
Events: array of TPerformanceEvent;
// ��������� ��������� ������ �������
// Starts measurement of a new event.
procedure StartEvent(EventName: string);
// ������������� ��������� �������. EventName �� ������ ���������
// ������ ��� �����������.
//Stops event measurement. You can indicate EventName for
// illustration purposes only.
procedure StopEvent(EventName: string = '');
// ���������� ���������� �� ��������� ������������ �������
// Returns event duration measurement information
function GetEventsAsString(EvOp: TGetPerformanceEventsOptions): string;
end;
var
PerformanceFrequency: Int64;
// ���������� �����, ������� ����� ������������ ��� ����� �������
// ��������� ��������� ����������
// The number of ticks that must be ignored to more accurately measure time intervals
PerformanceIgnoredTicks: Int64;
implementation
@ -135,13 +134,13 @@ var
ACounter: Int64;
begin
if FIsRunning then
begin // ���� ��������� ��������, �� ���������� ������� ��������
begin // If measurements are started, then return the current value
QueryPerformanceCounter(ACounter);
Result := ACounter - FStartCounter - PerformanceIgnoredTicks;
if Result < 0 then
Result := 0;
end else
begin // ��������� ����������� - ���������� �������� �� ������ ��������
begin // Measurements stopped - return the value at the time of stop
Result := FElapsedTicks
end;
@ -158,7 +157,7 @@ procedure TPerformance.Start;
begin
FIsRunning := True;
FElapsedTicks := 0;
// ����������� ������� � ����� ����� ������
// Request a counter at the very end of the method
QueryPerformanceCounter(FStartCounter);
end;
@ -166,7 +165,7 @@ procedure TPerformance.Stop;
var
ACounter: Int64;
begin
// ����������� ������� � ����� ������ ������
// Request a counter at the very beginning of the method
QueryPerformanceCounter(ACounter);
FIsRunning := False;
FElapsedTicks := ACounter - FStartCounter - PerformanceIgnoredTicks;
@ -312,14 +311,14 @@ begin
QueryPerformanceCounter(p1);
QueryPerformanceCounter(p2);
PerformanceIgnoredTicks := p2 - p1;
// ���� ��� �� ��������� �������������, �� ���������� ���������:
// If you do not need adjustment, then just assign:
// PerformanceIgnoredTicks := 0
end;
initialization
// �������� ������� ���������������� �������
// We get the frequency of the high-frequency timer
QueryPerformanceFrequency(PerformanceFrequency);
if PerformanceFrequency = 0 then
PerformanceFrequency := 1; // ����� �� ���� ������ ������� �� ����
PerformanceFrequency := 1; // To avoid division by zero
CalcIgnoredPerformanceTicks;
end.