Mailing List Archive

`time.perf_counter_ns` always a 64-bit int?
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?
--
https://mail.python.org/mailman/listinfo/python-list
Re: `time.perf_counter_ns` always a 64-bit int? [ In reply to ]
> 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
>

--
https://mail.python.org/mailman/listinfo/python-list
Re: `time.perf_counter_ns` always a 64-bit int? [ In reply to ]
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!"