On Sun, Jul 18, 2010 at 11:55 PM, Caspar Zhang <[email protected]> wrote:
>
> ----- "Garrett Cooper" <[email protected]> wrote:
>
>>
>>     The fact that the test is using time(3) to calculate the elapsed
>> period instead of clock_gettime is dubious at best, because the
>> precision of time is in seconds. Maybe it should be converted to
>> clock_gettime calls for improved precision?
>
> Use clock_gettime instead of time(3), patch attached.

Looks better, but being strict it's still buggy. POSIX defines struct
timespec as:

The <time.h> header shall declare the structure timespec, which has at
least the following members:

time_t  tv_sec    Seconds.
long    tv_nsec   Nanoseconds.

So you're losing precision in one case, and time_t can be variable
(the spec for types.h is rather fluid):

time_t and clock_t shall be integer or real-floating types.

The (struct timeval *) casts are also unnecessary because you're
getting the address of a struct timeval object (which is in both cases
struct timeval*).

> Another question, since POSIX.1-2008 marks gettimeofday() as obsolete
> (man gettimeofday), should the usec test part be changed to
> clock_getime as well?

Sure, if you want.

Thanks!
-Garrett

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to