diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2012-03-28 00:54:15 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2012-03-28 00:54:15 (GMT) |
commit | ad95c2d25c5fe5c4c88b73de2c60722ba56572e9 (patch) | |
tree | 91d69b740b60b5d393e303cac839b3e506e5431e /Modules/timemodule.c | |
parent | 74eb6c0e8bcdab65ac10f5a0a880768eef15a601 (diff) | |
download | cpython-ad95c2d25c5fe5c4c88b73de2c60722ba56572e9.zip cpython-ad95c2d25c5fe5c4c88b73de2c60722ba56572e9.tar.gz cpython-ad95c2d25c5fe5c4c88b73de2c60722ba56572e9.tar.bz2 |
time.time() now uses clock_gettime(CLOCK_REALTIME) if available
clock_gettime(CLOCK_REALTIME) has a better resolution than gettimeofday().
time.time() falls back on gettimeofday() (and then on other functions) on
error.
Diffstat (limited to 'Modules/timemodule.c')
-rw-r--r-- | Modules/timemodule.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c index c99c0a9..f44e0c4 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1088,6 +1088,17 @@ static PyObject* floattime(void) { _PyTime_timeval t; +#ifdef HAVE_CLOCK_GETTIME + struct timespec tp; + int ret; + + /* _PyTime_gettimeofday() does not use clock_gettime() + because it would require to link Python to the rt (real-time) + library, at least on Linux */ + ret = clock_gettime(CLOCK_REALTIME, &tp); + if (ret == 0) + return PyFloat_FromDouble(tp.tv_sec + tp.tv_nsec * 1e-9); +#endif _PyTime_gettimeofday(&t); return PyFloat_FromDouble((double)t.tv_sec + t.tv_usec * 1e-6); } |