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

Victor Stinner victor.stinner at gmail.com
Wed Feb 15 18:58:54 CET 2012


>> 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


More information about the Python-Dev mailing list