Einzelnen Beitrag anzeigen

Rollo62

Registriert seit: 15. Mär 2007
3.896 Beiträge
 
Delphi 12 Athens
 
#2

AW: Unterschied TStopwatch.Elapsed.Milliseconds und TStopwatch.ElapsedMilliseconds

  Alt 24. Nov 2022, 17:07
Interessant, ist mir noch nie aufgefallen, ich habe immer ElapsedMilliseconds genutzt.
Ich habe hier nur D11, ist aber bestimmt gleich geblieben

Identisch sind die Funktionen nicht, bei (1) ist noch ein mod 1000 drin und gibt anscheinend nur den Rest der Millisekunden vom jeweiligen Zeitobjekt zurück.
Wobei (2) mit ElapsedMilliseconds die kompletten ms zurückgibt, ohne Begrenzung.

Delphi-Quellcode:

(1)
     LStp.Elapsed.Milliseconds;

function TStopwatch.GetElapsed: TTimeSpan;
begin
  Result := TTimeSpan.Create(GetElapsedDateTimeTicks);
end;

function TTimeSpan.GetMilliseconds: Integer;
begin
  Result := Integer((FTicks div TicksPerMillisecond) mod 1000);
end;


(2)
     LStp.ElapsedMilliseconds;

function TStopwatch.GetElapsedMilliseconds: Int64;
begin
  Result := GetElapsedDateTimeTicks div TTimeSpan.TicksPerMillisecond;
end;

  public const
    TicksPerMillisecond = 10000;

function TStopwatch.GetElapsedDateTimeTicks: Int64;
begin
  Result := ElapsedTicks;
  if FIsHighResolution then
    Result := Trunc(Result * TickFrequency);
end;
Wenn Du was Ähnliches haben willst hilft vielleicht das Elapsed.TotalMilliseconds, ist aber dann ein Double.
Delphi-Quellcode:
function TTimeSpan.GetTotalMilliseconds: Double;
begin
  Result := MillisecondsPerTick;
  Result := FTicks * Result;
  if Result > MaxMilliseconds then
    Result := MaxMilliseconds
  else if Result < MinMilliseconds then
    Result := MinMilliseconds;
end;

Geändert von Rollo62 (24. Nov 2022 um 17:10 Uhr)
  Mit Zitat antworten Zitat