如何计算函数的经过时间? [英] How to calculate elapsed time of a function?

查看:135
本文介绍了如何计算函数的经过时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



然后我想显示使用的时间并将其与另一个函数进行比较,组件,以便了解更快的功能。

解决方案

您可以使用 TStopwatch System.Diagnostics 单位,以使用系统的高分辨率性能计数器来衡量已用时间。

  var 
秒表:TStopwatch;
已过期:TTimeSpan;
....
秒表:= TStopwatch.StartNew;
DoSomething;
已过期:=秒表。

要从时间跨度读取时间值,请执行以下操作:

  var 
秒:双;
....
Seconds:= Elapsed.TotalSeconds;


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 function.

解决方案

You can use TStopwatch from the System.Diagnostics unit to measure elapsed time using the system's high-resolution performance counter.

var
  Stopwatch: TStopwatch;
  Elapsed: TTimeSpan;
....
Stopwatch := TStopwatch.StartNew;
DoSomething;
Elapsed := Stopwatch.Elapsed;

To read a time value in seconds, say, from a time span, do this:

var
  Seconds: Double;
....
Seconds := Elapsed.TotalSeconds;

这篇关于如何计算函数的经过时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆