【发布时间】:2012-10-01 21:03:57
【问题描述】:
我无法解释我生成的日志中的 difftime 数量:
我测量一些方法调用的持续时间,并使用以下语法记录它:
time_t end, start ;
time(&start);
obj->sqp_func(this);
time(&end);
t_time = difftime(end, start) ;
sqp << "time " << endl ;
sqp << (double) end << endl ;
sqp << (double) start << endl ;
sqp << (double) t_time << endl ;
其中sqp是ofstream类型。
我知道了,应该在哪里打印 t_time(类型为 double),值 210。
是 210 秒吗?它是被截断的,还是被截断的?
例如,如何在几秒钟内获得最多 2 个浮点数的结果?
【问题讨论】:
-
更好的是,使用
std::chrono。 -
@MarkGarcia 我猜是一些 C++11?谁可以编译C++11 BTW(哪个版本的VS?)?
-
VS2010 对 c++11 有一些支持(支持chrono)。 VS2012 全面支持 c++11。
-
@MarkGarcia 实际上 VS2010 没有有
std::chrono。 “VS2012 全面支持 c++11” - 好吧,为了清楚这个库。虽然这还不完整,但至少缺少 C++11 数学函数和用于控制浮点环境的函数。 -
@MarkGarcia 你知道如何使用 difftime 设置精度以在 ostream 中打印吗?我正在使用
outpt << std::fixed << std::setprecision(10) << (double) time << endl ;,它正在打印...浮点后有10个零,没有提高精度。