我想知道如何计算Delphi中函数消耗的时间。
然后我想显示使用的时间并与其他功能或组件进行比较,以了解更快的功能。
最佳答案
您可以使用 System.Diagnostics
单元中的 TStopwatch
来通过系统的高分辨率性能计数器来测量耗时。
var
Stopwatch: TStopwatch;
Elapsed: TTimeSpan;
....
Stopwatch := TStopwatch.StartNew;
DoSomething;
Elapsed := Stopwatch.Elapsed;
要读取以秒为单位的时间值(例如,从一个时间跨度),请执行以下操作:
var
Seconds: Double;
....
Seconds := Elapsed.TotalSeconds;
关于delphi - 如何计算函数的运行时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16984360/