milt@mem.pe-nelson.com (Milt Ratcliff) (06/11/91)
I am trying to make several programs POSIX compliant. As part of the effort I am confronted with a need to convert routines which measure time. To provide formatted time strings, the strftime function is relatively easy to use. To provide the input to the strftime function, gettimeofday has been used and the seconds part of the timeval struct(tv_sec) passed to localtime. This, in turn, has provided the tm struct used by strftime. The use of gettimeofday has served a dual purpose, the first described above. In addition it provides a very high resolution timer capatility, returning the elapsed time in u-seconds since Jan. 1, 1970. Obviously, the resolution is actually controlled by the hardware clock, but it will provide resolution within that restraint. My question concerns a replacement for the gettimeofday function which will provide this level of timing resolution within a POSIX routine. The POSIX documents I am reading imply the use of either clock() or times(). My intention is to use times() which is required by POSIX while clock() is required by Standard C but not POSIX. Also, I am not sure of the meaning of 'Standard C'(I am using "POSIX Programmer's Guide by Donald Lewine, O'Reilly & Associates, Inc.). Is this the correct approach and can I expect the results to be equivalent to the data obtained from gettimeofday? Thanks, milt Milt Ratcliff milt@pe-nelson.com PE-Nelson -- Thanks, milt Milt Ratcliff milt@pe-nelson.com PE-Nelson
milt@mem.pe-nelson.com (Milt Ratcliff) (06/11/91)
I am trying to make several programs POSIX compliant. As part of the effort I am confronted with a need to convert routines which measure time. To provide formatted time strings, the strftime function is relatively easy to use. To provide the input to the strftime function, gettimeofday has been used and the seconds part of the timeval struct(tv_sec) passed to localtime. This, in turn, has provided the tm struct used by strftime. The use of gettimeofday has served a dual purpose, the first described above. In addition it provides a very high resolution timer capatility, returning the elapsed time in u-seconds since Jan. 1, 1970. Obviously, the resolution is actually controlled by the hardware clock, but it will provide resolution within that restraint. My question concerns a replacement for the gettimeofday function which will provide this level of timing resolution within a POSIX routine. The POSIX documents I am reading imply the use of either clock() or times(). My intention is to use times() which is required by POSIX while clock() is required by Standard C but not POSIX. Also, I am not sure of the meaning of 'Standard C'(I am using "POSIX Programmer's Guide by Donald Lewine, O'Reilly & Associates, Inc.). Is this the correct approach and can I expect the results to be equivalent to the data obtained from gettimeofday? Thanks, Milt Milt Ratcliff milt@pe-nelson.com PE-Nelson Cupertino, CA
diamond@jit533.swstokyo.dec.com (Norman Diamond) (06/11/91)
In article <298@mem.pe-nelson.com> milt@mem.pe-nelson.com (Milt Ratcliff) writes: >I am trying to make several programs POSIX compliant. As part of the effort I >am confronted with a need to convert routines which measure time. >My question concerns a replacement for the gettimeofday function which will >provide [high] level of timing resolution within a POSIX routine. The POSIX >documents I am reading imply the use of either clock() or times(). My >intention is to use times() which is required by POSIX while clock() is >required by Standard C but not POSIX. The clock() function returns CPU usage, not time of day. If you want your program to be strictly conformant to ANSI C (i.e. usable on (approximately) all ANSI-conformant processors), then you want the time() function. But you hint that this may not have sufficient resolution for your application. So you only want to run on POSIX-conformant processors, and you can call a POSIX function which meets your needs; that might be times(). >Also, I am not sure of the meaning of 'Standard C' In this newsgroup, it seems to mean the ANSI 1989 standard, and the corresponding ISO standard. Also, a processor-supplied definition of the macro __STDC__ with value 1 is supposed to mean this standard (though some non-ANSI vendors have caused problems with this). >can I expect the results to be equivalent to [...] gettimeofday? The POSIX newsgroups might be more helpful for you. -- Norman Diamond diamond@tkov50.enet.dec.com If this were the company's opinion, I wouldn't be allowed to post it. Permission is granted to feel this signature, but not to look at it.