Date: Thu, 10 Jul 1997 02:05:12 -0500 From: Kent Vander Velden <graphix@iastate.edu> To: freebsd-questions@freebsd.org Subject: getrusage and small system time usages Message-ID: <33C489A8.2781E494@iastate.edu>
next in thread | raw e-mail | index | archive | help
Often I use getrusage() to time a section of code. However, generally
I get frustrated with the effecitveness of getrusage() since I often
get negative numbers! Tonight, I got negative numbers again and
thought perhaps someone could suggest a reason for this. Even if
the interval that I am timing is really small, I see no reason the
value would be negative. Zero would be more believable.
The following contains code that I was using:
class Clock {
protected:
rusage start;
rusage end;
public:
Clock() { getrusage(RUSAGE_SELF, &start); }
~Clock() {
getrusage(RUSAGE_SELF, &end);
double st=(end.ru_stime.tv_sec - start.ru_stime.tv_sec
+(end.ru_stime.tv_usec - start.ru_stime.tv_usec)/(double)10e6);
double ut=(end.ru_utime.tv_sec - start.ru_utime.tv_sec
+(end.ru_utime.tv_usec - start.ru_utime.tv_usec)/(double)10e6);
cout << "System time requirement: " << st << " sec." << endl
<< "User time requirement: " << ut << " sec." << endl
<< "Total time requirement: " << st+ut << " sec." << endl;
}
};
Thanks.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?33C489A8.2781E494>
