[Datetime-SIG] PEP-0500 (Alternative datetime arithmetic) Was: PEP 495 ... is ready ...

Alexander Belopolsky alexander.belopolsky at gmail.com
Thu Aug 20 01:21:04 CEST 2015


On Wed, Aug 19, 2015 at 1:25 PM, Guido van Rossum <guido at python.org> wrote:

> Rather than prolonging the debate, let me just reject PEP 500.


That is certainly within your powers, but before you do, let me
substantiate my claim about 10x performance penalty.

$ python3 -m timeit -s "from datetime import datetime, timezone; t =
datetime.now(timezone.utc); l = t.astimezone()" "l - t"
1000000 loops, best of 3: 0.448 usec per loop
$ python3 -m timeit -s "from datetime import datetime, timezone; t =
datetime.now(); l = t" "l - t"
10000000 loops, best of 3: 0.0444 usec per loop

Currently, subtracting aware datetimes with the same tzinfo incurs no
penalty

$ python3 -m timeit -s "from datetime import datetime, timezone; t =
datetime.now(timezone.utc); l = t" "l - t"
10000000 loops, best of 3: 0.0436 usec per loop

With PEP 500, we can have timeline arithmetic without the overhead of two
round trips to tzinfo.   I will be happy if someone would demonstrate how
to achieve the same by simpler means.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/datetime-sig/attachments/20150819/9eb5639b/attachment.html>


More information about the Datetime-SIG mailing list