[issue44307] date.today() is 2x slower than datetime.now().date()

Paul Ganssle report at bugs.python.org
Fri Jun 4 15:55:33 EDT 2021


Paul Ganssle <p.ganssle at gmail.com> added the comment:

Yeah, I knew this was slower and it's been on my long list to look at it (tied to this is the fact that `datetime.today()` is basically just a slow version of `datetime.now()`, in defiance of user expectations).

My inclination is that we shouldn't re-implement `fromtimestamp` in `date.today`, but rather call `date_fromtimestamp` in the fast path. I believe that incurs the overhead of creating one additional Python object (an integer), but if it's a sufficiently significant speedup, we could possibly refactor `date_fromtimestamp` to a version that accepts a C integer and a version that accepts a Python integer, then call the version accepting a C integer.

I think this won't give any speedup to `datetime.today`, since `datetime.today` will still take the slow path. If we care about this, we *may* be able to implement `datetime.today` as an alias for `datetime.now(None)`, assuming there are no behavioral differences between the two.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44307>
_______________________________________


More information about the Python-bugs-list mailing list