[Python-ideas] strptime without second argument as an inverse to __str__

Alexander Belopolsky alexander.belopolsky at gmail.com
Thu Aug 7 02:29:12 CEST 2014


On Wed, Aug 6, 2014 at 7:55 PM, Andrew Barnert <abarnert at yahoo.com> wrote:

> More readable maybe, but more efficient? You're doing the same work, plus
> string parsing; you're eliminating two parameters (but only if you use
> *args) at the cost of three locals; by any measure it's less efficient.


>>> dis(lambda: date(2001, 1, 1))
  1           0 LOAD_GLOBAL              0 (date)
              3 LOAD_CONST               1 (2001)
              6 LOAD_CONST               2 (1)
              9 LOAD_CONST               2 (1)
             12 CALL_FUNCTION            3
             15 RETURN_VALUE
>>> dis(lambda: date('2001-01-01'))
  1           0 LOAD_GLOBAL              0 (date)
              3 LOAD_CONST               1 ('2001-01-01')
              6 CALL_FUNCTION            1
              9 RETURN_VALUE

Since parsing will be done in C, it's cost can be made negligible.  In
implementations other than CPython, YMMV.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140806/9717dc0a/attachment.html>


More information about the Python-ideas mailing list