Advertisement

Two quick Posix questions

Started by February 15, 2004 05:37 PM
7 comments, last by rypyr 20 years, 7 months ago
1) Is there an equivalent Posix call for timeGetTime()? I want to be able to time a function to the millisecond level (at least). Is it clock_gettime(CLOCK_REALTIME, &timespec) and then look at timespec''s tv_nsec member? 2) Is there a set of Posix documentation available that is as good as MSDN or the Java API docs? What I''ve downloaded is IEEE Std 1003.1-2001, but is there something nicer? For instance, I don''t see where structures are listed all in a nice list (klike all the system interfaces are). I have to click on clock_gettime(), then click on time.h link and scroll to see the bit about the timespec structure. Thanks, Jeff
Another option I''ve seen is:

clock_t clock();

which returns the CPU time used since the process was invoked (I think). You need to divide the result by CLOCKS_PER_SEC to get the time in seconds, so I assume I''d go:

(clock()*1000)/CLOCK_PER_SEC

to get the value in milliseconds...

Anyone? Anyone?

Regards,
Jeff
Advertisement
1) Yes, but you should compare the seconds value as well, you never know if the last frame took more than a second to render.
2) "man clock_gettime" seems to work well for me (under linux).
Abdulla, do you know about clock()?

quote: Original post by abdulla
2) "man clock_gettime" seems to work well for me (under linux).


This is under the mistaken impression that I KNOW about this function already...what if I want to browse around for functions starting with clock_? Then I want to see what a timespec struct is about?

then use google.

an clock(), IIRC, may return one of:
(a) time since the program started
(b) time the program has executed in the processor.

I kinda suspect (b), which would mean you get seconds of time after minutes of running... (potentially)
You can always do "man -a clock*", which is actually how I found it, I have no idea why I did that, guess I was bored one day.
Advertisement
quote: Original post by rypyr
This is under the mistaken impression that I KNOW about this function already...what if I want to browse around for functions starting with clock_? Then I want to see what a timespec struct is about?

man -k clock
or
apropos clock
I use gettimeofday() for all my time requirements.
quote: Original post by debaere
I use gettimeofday() for all my time requirements.


Finally! Thank you sir! The call to clock() did not seem to meet my time requirements as it was CPU clock ticks instead of actual time.

This topic is closed to new replies.

Advertisement