#1 2017-12-20 20:19:28

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

function TPrecisionTimer.Time: RawUTF8;

I'm using TPrecisionTimer to time a long running procedure. Would it be possible to change the Time function to return hours and minutes as well?

Changing MicroSecToString in SynCommons.pas seems to work:

function MicroSecToString(Micro: QWord): RawUTF8;
  function TwoDigitToString(value: cardinal): RawUTF8;
  var L: integer;
  begin
    UInt32ToUtf8(value,result);
    L := length(result);
    if L=1 then
      result := '0.0'+result else // '3' -> '0.03'
    if L=2 then
      result := '0.'+result else // '35' -> '0.35'
      insert('.',result,L-1); // '103' -> '1.03'
  end;
  var seconds: Cardinal;
begin
  if Micro<=0 then
    result := '0us' else
  if Micro<1000 then
    result := SmallUInt32UTF8[Micro]+'us' else
  if Micro<1000*1000 then
    result := TwoDigitToString(Int64Rec(Micro).Lo div 10)+'ms' else
  if Micro<1000*1000*60 then
    result := TwoDigitToString(Micro div (10*1000))+'s' else
  begin
    seconds := Micro div (1000*1000);
    if seconds < 60*60 then
      result := UInt32ToUtf8(seconds div 60)+'m '+UInt32ToUtf8(seconds mod 60)+'s'
    else
      result := UInt32ToUtf8(seconds div (60*60))+'h '+
                UInt32ToUtf8((seconds mod (60*60)) div 60)+'m '+
                UInt32ToUtf8(seconds mod 60)+'s'
  end;
end;

Offline

#2 2017-12-20 20:31:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: function TPrecisionTimer.Time: RawUTF8;

For a long-time running procedure, just use GetTickCount64.
The high-precision timer frequency may vary, so may not be accurate on some systems for a long-term process.

Offline

#3 2017-12-20 20:35:41

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Re: function TPrecisionTimer.Time: RawUTF8;

Okay, Thanks.

Offline

Board footer

Powered by FluxBB