• `time.perf_counter_ns` always a 64-bit int?

    From rmlibre@riseup.net@21:1/5 to All on Fri Sep 15 21:48:37 2023
    I'd like to capture the output of `time.perf_counter_ns()` as an 8-byte timestamp.

    I'm aware that the docs provide an undefined start value for that clock.
    I'm going to assume that means it can't be expected to fit within 8
    bytes. However, it would be rather convenient if it could. Does anyone
    know if any such platform agnostic assumption could be made for any
    fixed number of bytes, even if it isn't exactly 8 bytes?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Barry@21:1/5 to All on Sat Sep 16 09:52:45 2023
    On 15 Sep 2023, at 23:00, rmlibre--- via Python-list <python-list@python.org> wrote:

    I'd like to capture the output of `time.perf_counter_ns()` as an 8-byte timestamp.

    I'm aware that the docs provide an undefined start value for that clock.
    I'm going to assume that means it can't be expected to fit within 8
    bytes. However, it would be rather convenient if it could. Does anyone
    know if any such platform agnostic assumption could be made for any
    fixed number of bytes, even if it isn't exactly 8 bytes?

    If you read the source code the value is stored in a 64 bit int for unix and windows.

    There is a comment that it covers the range of +-232 years.

    Barry

    --
    https://mail.python.org/mailman/listinfo/python-list


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter J. Holzer@21:1/5 to rmlibre--- via Python-list on Sat Sep 16 14:28:20 2023
    On 2023-09-15 21:48:37 +0000, rmlibre--- via Python-list wrote:
    I'd like to capture the output of `time.perf_counter_ns()` as an 8-byte timestamp.

    I'm aware that the docs provide an undefined start value for that clock.
    I'm going to assume that means it can't be expected to fit within 8
    bytes.

    Theoretically this is true. The reference point could be the switch to
    the Gregorian calendar in the Vatican, the begin of the Christian era or
    the founding of Babylon, all of which were more than 2**63 seconds ago. However, using one of these dates would be impractical and defeat the
    purpose of the performance counters, which are supposed to be high
    resolution, monotonic and independent of political influences. So the
    reference point is usually the time the system was booted or something
    similar.

    However, it would be rather convenient if it could.

    Unless you expect your system to have an uptime in excess of 292 years,
    don't worry.

    hp

    --
    _ | Peter J. Holzer | Story must make more sense than reality.
    |_|_) | |
    | | | hjp@hjp.at | -- Charles Stross, "Creative writing
    __/ | http://www.hjp.at/ | challenge!"

    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmUFn18ACgkQ8g5IURL+ KF2WNg/+PLvQx1c4+B6M2Z7xpMBMtvEJOIMpBW1yffzYA68GUD5fnfOgBetGFE0A VPAi/ZpDS9P58KNhV7WufMQMzo0gRD4L0LGSPxcMQrE1Kjs1w/XBkFlhWKor0VE2 kzsYUEixofn3B1VJILm5G1o1HsHqJuWQTV4qdkja0NlPcqTdQNfY1i/34xXL4gQI xtmvfiRBgjp2bRoO6x+dzqyvEmCAFrMixHPA8qlQ0oeNEGIy1j3eJahpJJoneZUo EAUS4+OUzA/VcS4mDM8MLW/8m8d53iBycj1djU0WZoU1XKCjfTIoOrvx1KJnq7xQ knTsl6q6fVWlIssg4IAIU8xD7cAT2uHF984r1x12LQ1c+AY/Uc55WA+WBIS5RPJN uFDK5d4DQIVz3a2EOt3cce65G1RXADMbb6qQxrg6VNpxgtXb3OfXYM222SAsaBGO F7x1MUYK0LTX6cASRpdG6Pq3rkuG9X97oaVEjcacNeHjbJPpfLaMzbrxTu0rjvTx BHoMoVn4F/ERnFcorql7lzt9O0t/52mLa2RCvGD3CB0RT3roTfYQO4PM7pkuMR4X i7ShFu8J7s+/emfweQkN64zvvXV5hspnheKXO6kk74ycOZavPCtsUwuTOGjYW13J b86FFvUxJ+3L37EtF1VSwJGQw/pBDXAqZwsCPSC