osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] PEP 410 (Decimal timestamp): the implementation is ready for a review


So using floats we can match 100ns precision, right?

On Wed, Feb 15, 2012 at 9:58 AM, Victor Stinner
<victor.stinner at gmail.com> wrote:
>>> Linux supports nanosecond timestamps since Linux 2.6, Windows supports
>>> 100 ns resolution since Windows 2000 or maybe before. It doesn't mean
>>> that Windows system clock is accurate: in practical, it's hard to get
>>> something better than 1 ms :-)
>>
>> Well, do you think the Linux system clock is nanosecond-accurate?
>
> Test the following C program:
> ------------
> #include <stdio.h>
> #include <time.h>
>
> int main(int argc, char **argv, char **arge) {
> ?struct timespec tps, tpe;
> ?if ((clock_gettime(CLOCK_REALTIME, &tps) != 0)
> ?|| (clock_gettime(CLOCK_REALTIME, &tpe) != 0)) {
> ? ?perror("clock_gettime");
> ? ?return -1;
> ?}
> ?printf("%lu s, %lu ns\n", tpe.tv_sec-tps.tv_sec,
> ? ?tpe.tv_nsec-tps.tv_nsec);
> ?return 0;
> }
> ------------
> Compile it using gcc time.c -o time -lrt.
>
> It gives me differences smaller than 1000 ns on Ubuntu 11.10 and a
> Intel Core i5 @ 3.33GHz:
>
> $ ./a.out
> 0 s, 781 ns
> $ ./a.out
> 0 s, 785 ns
> $ ./a.out
> 0 s, 798 ns
> $ ./a.out
> 0 s, 818 ns
> $ ./a.out
> 0 s, 270 ns
>
> Victor
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org



-- 
--Guido van Rossum (python.org/~guido)