[델파이/Delphi] 프로세스 동작 시간 측정하기 - TStopWatch 예제
프로세스의 동작 시간을 측정, 비교하기 위한 TStopWatch API 예제.
- 코드 :
procedure StopWatch;
var
stopWatch :TStopWatch; //System.Diagnostics
elapsed: TTimeSpan; //System.TimeSpan
i :integer;
seconds :Double;
begin
try
stopwatch := TStopwatch.StartNew;
for i := 0 to 1000000 do
begin
//doSomething..
end;
elapsed := stopwatch.elapsed; //stopWatch 의 시간 경과를 elapsed 객체에 저장.
seconds := elapsed.TotalSeconds; //double으로 초단위 시간을 return.
Showmessage(FloatToStr(seconds)); //e.g.) 0.0014983 표시.
finally
stopWatch.Stop;
end;
end;
* 사용방법이 간단해서 좋다.
* 리팩터링할 때 유용하게 사용할 수 있을 것 같다.
- 코드 출처 :
https://stackoverflow.com/questions/16984360/how-to-calculate-elapsed-time-of-a-function
How to calculate elapsed time of a function?
I would like to know how to calculate the time consumed for a function in Delphi. Then I wanted to show the used time and compare it with another function or component so as to know the faster fun...
stackoverflow.com
'Delphi' 카테고리의 다른 글
[델파이/Delphi] Directory 내용 불러오기, File 내용 추출하기 예제 (0) | 2022.02.17 |
---|---|
[델파이/Delphi] 자료구조 - Queue (0) | 2022.01.19 |
[델파이/Delphi] TStringBuilder (0) | 2021.12.14 |
[델파이/Delphi] Generic(제네릭) 간단 사용 예제 (0) | 2021.11.27 |
[델파이/Delphi] TStringList - Delimiter & LineBreak, CommaText 예제 (1) | 2021.11.22 |