Boost时间-计时(精度:秒)

Boost时间-计时(精度:秒),第1张

Boost时间-计时(精度:秒)
#include 
#include 
#include 


int main(int argc, char **argv) {
	boost::timer t;
	printf("统计间隔上限: %.2fhn", t.elapsed_max() / 3600);
	printf("统计最小间隔: %.2fsn", t.elapsed_min());
	printf("n开始执行任务...n");
	Sleep(3000);
	printf("当前任务结束,已耗费时间: %.2fsn", t.elapsed());

	printf("nn>>>可以重置统计时间,便于统计另一个任务的耗时<< 

运行结果:

说明:

  1.  封装标准库头文件里面的std::clock()来实现的计时
  2. 每秒的clock数由宏CLOCKS_PER_SEC定义
  3. 定义变量就开始了计时:boost::timer t;
  4. 通过调用t.restart()重新计时
  5. 计时精度为秒,因而不适合高精度的时间测量
  6. 最大时间跨度:t.elapsed_max(),适用于短时间的统计,不适合以天、月甚至年作为时间单位来统计

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5595243.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存