简体   繁体   中英

C++ time.h difftime

I am in trouble with interpreting difftime quantity in a log I have produced:

I measure duration for some method call, and I log it, with this syntax:

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 ;  

where sqp is of ofstream type.

I get, where t_time (with type double ) should be printed, the value 210.

Are those 210 seconds? Is it truncated, or floored?

How can I get result in seconds up to 2 floating points for instance?

You need to use a timer with a higher resolution (if you can not use C++11). - Like this . For your case clockid_t - CLOCK_MONOTONIC .

difftime 以秒difftime返回double类型的差异 http://www.cplusplus.com/reference/clibrary/ctime/difftime/-有关详细说明,请参见此内容

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM