본문 바로가기

운동하는 개발자/Delphi

delphi, lazarus 동작시간 계산

728x90

코드의 특정 부분의 동작 시간(실행시간)을 로그로 남기고 싶을 때

uses
 dateutils; //datetime 계산을 위한 함수


procedure workfunction;
var
    LStartTime : TDateTime; //시작시간
    LWorkTime :  Int64; //동작시간
begin

    LStartTime := Now; // 시작시간 기록
    
    for( 블라블라);
    
    LWorkTime := MilliSecondsBetween(Now,LStartTime);
end;    
    
    

 

MilliSecondsBetween() 함수는 ms단위의 값으로 리턴을 주고 각 단위로 계산하는 함수들은 아래와 같다

 

Function YearsBetween(const ANow, AThen: TDateTime; AExact : Boolean = False): Integer;
Function MonthsBetween(const ANow, AThen: TDateTime; AExact : Boolean = False): Integer;
Function WeeksBetween(const ANow, AThen: TDateTime): Integer;
Function DaysBetween(const ANow, AThen: TDateTime): Integer;
Function HoursBetween(const ANow, AThen: TDateTime): Int64;
Function MinutesBetween(const ANow, AThen: TDateTime): Int64;
Function SecondsBetween(const ANow, AThen: TDateTime): Int64;
Function MilliSecondsBetween(const ANow, AThen: TDateTime): Int64;
Procedure PeriodBetween(const ANow, AThen: TDateTime; Out Years, months, days : Word);      


 

728x90