timestamp: Switch to a slightly faster datetime_to_timestamp.

This is quite a bit faster:
```
%timeit calendar.timegm(now.timetuple())
    2.91 µs ± 361 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

%timeit int(now.timestamp())
    539 ns ± 27 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
```

This is particularly important for the presence endpoint, which is a
tight loop of serializing datetimes.
This commit is contained in:
Alex Vandiver 2023-02-23 05:36:50 +00:00 committed by Tim Abbott
parent 95867e6f3e
commit 97a5690f55
1 changed files with 1 additions and 2 deletions

View File

@ -1,4 +1,3 @@
import calendar
import datetime
@ -47,4 +46,4 @@ def timestamp_to_datetime(timestamp: float) -> datetime.datetime:
def datetime_to_timestamp(dt: datetime.datetime) -> int:
verify_UTC(dt)
return calendar.timegm(dt.timetuple())
return int(dt.timestamp())