Question

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 sqpis 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?

Was it helpful?

Solution

difftime returns difference in seconds of type double http://www.cplusplus.com/reference/clibrary/ctime/difftime/ - see this for detailed explanations

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top