more accurate version of scope timer

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6856 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-10-20 13:29:24 +00:00
parent 41ba665813
commit 4cf86c52a1

View File

@ -31,22 +31,29 @@
// callToMeasure() ;
// }
//
#include <sys/time.h>
class RsScopeTimer
{
public:
RsScopeTimer(const std::string& name)
{
_t = clock() ;
timeval tv ;
gettimeofday(&tv,NULL) ;
_seconds = (tv.tv_sec % 10000) + tv.tv_usec/1000000.0f ; // the %1000 is here to allow double precision to cover the decimals.
_name = name ;
}
~RsScopeTimer()
{
clock_t s = clock() ;
std::cerr << "Time for \"" << _name << "\": " << (s-_t)/(float)CLOCKS_PER_SEC << " secs" << std::endl;
timeval tv ;
gettimeofday(&tv,NULL) ;
double ss = (tv.tv_sec % 10000) + tv.tv_usec/1000000.0f ;
std::cerr << "Time for \"" << _name << "\": " << ss - _seconds << std::endl;
}
private:
clock_t _t ;
std::string _name ;
double _seconds ;
};