This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: building something with nanotime


Jim Stapleton wrote:

> although not likely, the code may cross a day threshold, and
> gettimeofday could be problematic. What is the simplest way to get a
> time interval on something that may cross a day threshold (in ms or
> preferrably ns?). I know clock() can get me ticks, but it'll take work
> to conver that to second (any simple way to do that)? I understand
> clock is for the given thread, and not absolute time, but both may be
> relevant at some point.

Despite 'day' in its name, gettimeofday() has nothing to do with days. 
Its return value is seconds since the epoch.

http://www.opengroup.org/onlinepubs/009695399/functions/gettimeofday.html
http://www.gnu.org/software/libc/manual/html_node/High_002dResolution-Calendar.html

However if you are trying to measure performance of an operation you
shouldn't use calendar time, you should use processor time.  Converting
to seconds is done by simply dividing by CLOCKS_PER_SEC, nominally one
million.

http://www.opengroup.org/onlinepubs/009695399/functions/times.html
http://www.gnu.org/software/libc/manual/html_node/Processor-Time.html

Brian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]