#include <stdio.h>
#include <windows.h>
#include <boost/progress.hpp>
int main(int argc, char **argv) {
boost::progress_timer t;
printf("\n开始执行任务...\n");
Sleep(3000);
printf("当前任务结束,已耗费时间: %.2fs\n", t.elapsed());
printf("\n\n>>>可以重置统计时间,便于统计另一个任务的耗时<<<\n");
printf("\n开始执行任务...\n");
t.restart();
Sleep(2000);
printf("当前任务结束,已耗费时间: %.2fs\n", t.elapsed());
return 0;
}
运行结果
说明:
- 与timer一样可以用于计时,是timer派生的类,timer的方法progress_timer一样可以用
- 不同的是,progress_timer在析构函数中会打印耗时,就像上面截图红框中的内容