| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent aa01011 commit 3df5c68
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -166,6 +166,9 @@ Functions | |||
| 166 | 166 | Return the time of the specified clock *clk_id*. Refer to | |
| 167 | 167 | :ref:`time-clock-id-constants` for a list of accepted values for *clk_id*. | |
| 168 | 168 | ||
| 169 | + Use :func:`clock_gettime_ns` to avoid the precision loss caused by the | ||
| 170 | + :class:`float` type. | ||
| 171 | + | ||
| 169 | 172 | .. availability:: Unix. | |
| 170 | 173 | ||
| 171 | 174 | .. versionadded:: 3.3 | |
@@ -185,6 +188,9 @@ Functions | |||
| 185 | 188 | Set the time of the specified clock *clk_id*. Currently, | |
| 186 | 189 | :data:`CLOCK_REALTIME` is the only accepted value for *clk_id*. | |
| 187 | 190 | ||
| 191 | + Use :func:`clock_settime_ns` to avoid the precision loss caused by the | ||
| 192 | + :class:`float` type. | ||
| 193 | + | ||
| 188 | 194 | .. availability:: Unix. | |
| 189 | 195 | ||
| 190 | 196 | .. versionadded:: 3.3 | |
@@ -273,10 +279,17 @@ Functions | |||
| 273 | 279 | The reference point of the returned value is undefined, so that only the | |
| 274 | 280 | difference between the results of consecutive calls is valid. | |
| 275 | 281 | ||
| 282 | + Use :func:`monotonic_ns` to avoid the precision loss caused by the | ||
| 283 | + :class:`float` type. | ||
| 284 | + | ||
| 276 | 285 | .. versionadded:: 3.3 | |
| 286 | + | ||
| 277 | 287 | .. versionchanged:: 3.5 | |
| 278 | 288 | The function is now always available and always system-wide. | |
| 279 | 289 | ||
| 290 | + .. versionchanged:: 3.10 | ||
| 291 | + On macOS, the function is now system-wide. | ||
| 292 | + | ||
| 280 | 293 | ||
| 281 | 294 | .. function:: monotonic_ns() -> int | |
| 282 | 295 | ||
@@ -295,8 +308,14 @@ Functions | |||
| 295 | 308 | point of the returned value is undefined, so that only the difference between | |
| 296 | 309 | the results of consecutive calls is valid. | |
| 297 | 310 | ||
| 311 | + Use :func:`perf_counter_ns` to avoid the precision loss caused by the | ||
| 312 | + :class:`float` type. | ||
| 313 | + | ||
| 298 | 314 | .. versionadded:: 3.3 | |
| 299 | 315 | ||
| 316 | + .. versionchanged:: 3.10 | ||
| 317 | + On Windows, the function is now system-wide. | ||
| 318 | + | ||
| 300 | 319 | .. function:: perf_counter_ns() -> int | |
| 301 | 320 | ||
| 302 | 321 | Similar to :func:`perf_counter`, but return time as nanoseconds. | |
@@ -317,6 +336,9 @@ Functions | |||
| 317 | 336 | returned value is undefined, so that only the difference between the results | |
| 318 | 337 | of consecutive calls is valid. | |
| 319 | 338 | ||
| 339 | + Use :func:`process_time_ns` to avoid the precision loss caused by the | ||
| 340 | + :class:`float` type. | ||
| 341 | + | ||
| 320 | 342 | .. versionadded:: 3.3 | |
| 321 | 343 | ||
| 322 | 344 | .. function:: process_time_ns() -> int | |
@@ -581,6 +603,17 @@ Functions | |||
| 581 | 603 | :class:`struct_time` object is returned, from which the components | |
| 582 | 604 | of the calendar date may be accessed as attributes. | |
| 583 | 605 | ||
| 606 | + Use :func:`time_ns` to avoid the precision loss caused by the :class:`float` | ||
| 607 | + type. | ||
| 608 | + | ||
| 609 | + | ||
| 610 | + .. function:: time_ns() -> int | ||
| 611 | + | ||
| 612 | + Similar to :func:`~time.time` but returns time as an integer number of nanoseconds | ||
| 613 | + since the epoch_. | ||
| 614 | + | ||
| 615 | + .. versionadded:: 3.7 | ||
| 616 | + | ||
| 584 | 617 | ||
| 585 | 618 | .. function:: thread_time() -> float | |
| 586 | 619 | ||
@@ -595,6 +628,9 @@ Functions | |||
| 595 | 628 | returned value is undefined, so that only the difference between the results | |
| 596 | 629 | of consecutive calls in the same thread is valid. | |
| 597 | 630 | ||
| 631 | + Use :func:`thread_time_ns` to avoid the precision loss caused by the | ||
| 632 | + :class:`float` type. | ||
| 633 | + | ||
| 598 | 634 | .. availability:: Windows, Linux, Unix systems supporting | |
| 599 | 635 | ``CLOCK_THREAD_CPUTIME_ID``. | |
| 600 | 636 | ||
@@ -608,13 +644,6 @@ Functions | |||
| 608 | 644 | .. versionadded:: 3.7 | |
| 609 | 645 | ||
| 610 | 646 | ||
| 611 | - .. function:: time_ns() -> int | ||
| 612 | - | ||
| 613 | - Similar to :func:`~time.time` but returns time as an integer number of nanoseconds | ||
| 614 | - since the epoch_. | ||
| 615 | - | ||
| 616 | - .. versionadded:: 3.7 | ||
| 617 | - | ||
| 618 | 647 | .. function:: tzset() | |
| 619 | 648 | ||
| 620 | 649 | Reset the time conversion rules used by the library routines. The environment | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + :func:`time.perf_counter()` on Windows and :func:`time.monotonic()` on macOS | ||
| 2 | + are now system-wide. Previously, they used an offset computed at startup to | ||
| 3 | + reduce the precision loss caused by the float type. Use | ||
| 4 | + :func:`time.perf_counter_ns()` and :func:`time.monotonic_ns()` added in Python | ||
| 5 | + 3.7 to avoid this precision loss. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,7 @@ | |||
| 6 | 6 | #if defined(__APPLE__) | |
| 7 | 7 | #include <mach/mach_time.h> /* mach_absolute_time(), mach_timebase_info() */ | |
| 8 | 8 | ||
| 9 | - #if defined(__APPLE__) && defined(__has_builtin) | ||
| 9 | + #if defined(__APPLE__) && defined(__has_builtin) | ||
| 10 | 10 | # if __has_builtin(__builtin_available) | |
| 11 | 11 | # define HAVE_CLOCK_GETTIME_RUNTIME __builtin_available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) | |
| 12 | 12 | # endif | |
@@ -730,7 +730,7 @@ pygettimeofday(_PyTime_t *tp, _Py_clock_info_t *info, int raise) | |||
| 730 | 730 | } | |
| 731 | 731 | ||
| 732 | 732 | #ifdef HAVE_CLOCK_GETTIME_RUNTIME | |
| 733 | - } else { | ||
| 733 | + } else { | ||
| 734 | 734 | #endif | |
| 735 | 735 | ||
| 736 | 736 | #endif | |
@@ -822,7 +822,6 @@ pymonotonic(_PyTime_t *tp, _Py_clock_info_t *info, int raise) | |||
| 822 | 822 | ||
| 823 | 823 | #elif defined(__APPLE__) | |
| 824 | 824 | static mach_timebase_info_data_t timebase; | |
| 825 | - static uint64_t t0 = 0; | ||
| 826 | 825 | uint64_t ticks; | |
| 827 | 826 | ||
| 828 | 827 | if (timebase.denom == 0) { | |
@@ -859,8 +858,6 @@ pymonotonic(_PyTime_t *tp, _Py_clock_info_t *info, int raise) | |||
| 859 | 858 | "mach_timebase_info is too large"); | |
| 860 | 859 | return -1; | |
| 861 | 860 | } | |
| 862 | - | ||
| 863 | - t0 = mach_absolute_time(); | ||
| 864 | 861 | } | |
| 865 | 862 | ||
| 866 | 863 | if (info) { | |
@@ -871,9 +868,6 @@ pymonotonic(_PyTime_t *tp, _Py_clock_info_t *info, int raise) | |||
| 871 | 868 | } | |
| 872 | 869 | ||
| 873 | 870 | ticks = mach_absolute_time(); | |
| 874 | - /* Use a "time zero" to reduce precision loss when converting time | ||
| 875 | - to floatting point number, as in time.monotonic(). */ | ||
| 876 | - ticks -= t0; | ||
| 877 | 871 | *tp = _PyTime_MulDiv(ticks, | |
| 878 | 872 | (_PyTime_t)timebase.numer, | |
| 879 | 873 | (_PyTime_t)timebase.denom); | |
@@ -960,7 +954,6 @@ static int | |||
| 960 | 954 | win_perf_counter(_PyTime_t *tp, _Py_clock_info_t *info) | |
| 961 | 955 | { | |
| 962 | 956 | static LONGLONG frequency = 0; | |
| 963 | - static LONGLONG t0 = 0; | ||
| 964 | 957 | LARGE_INTEGER now; | |
| 965 | 958 | LONGLONG ticksll; | |
| 966 | 959 | _PyTime_t ticks; | |
@@ -1000,7 +993,6 @@ win_perf_counter(_PyTime_t *tp, _Py_clock_info_t *info) | |||
| 1000 | 993 | } | |
| 1001 | 994 | ||
| 1002 | 995 | QueryPerformanceCounter(&now); | |
| 1003 | - t0 = now.QuadPart; | ||
| 1004 | 996 | } | |
| 1005 | 997 | ||
| 1006 | 998 | if (info) { | |
@@ -1013,10 +1005,6 @@ win_perf_counter(_PyTime_t *tp, _Py_clock_info_t *info) | |||
| 1013 | 1005 | QueryPerformanceCounter(&now); | |
| 1014 | 1006 | ticksll = now.QuadPart; | |
| 1015 | 1007 | ||
| 1016 | - /* Use a "time zero" to reduce precision loss when converting time | ||
| 1017 | - to floatting point number, as in time.perf_counter(). */ | ||
| 1018 | - ticksll -= t0; | ||
| 1019 | - | ||
| 1020 | 1008 | /* Make sure that casting LONGLONG to _PyTime_t cannot overflow, | |
| 1021 | 1009 | both types are signed */ | |
| 1022 | 1010 | Py_BUILD_ASSERT(sizeof(ticksll) <= sizeof(ticks)); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments