Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #84615

Re: Why does argparse return None instead of [] if an append action isn't used?

References (4 earlier) <ta4ipbx9j3.ln2@news.ducksburg.com> <mailman.18151.1422288861.18130.python-list@python.org> <qotioft4iao.fsf@ruuvi.it.helsinki.fi> <ma5ssj$ars$1@ger.gmane.org> <CALwzid=rzENxp3GHQbcu5WrnFesEJQFD==DDfrDC=EcX4=_WjQ@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2015-01-26 11:26 -0700
Subject Re: Why does argparse return None instead of [] if an append action isn't used?
Newsgroups comp.lang.python
Message-ID <mailman.18156.1422296837.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Jan 26, 2015 at 11:23 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> $ python3 -m timeit 't = (1000, 2000, 3000)'
> 100000000 loops, best of 3: 0.0147 usec per loop
> $ python3 -m timeit 't = [1000, 2000, 3000]'
> 10000000 loops, best of 3: 0.0678 usec per loop
> $ python3 -m timeit 't = tuple(range(10000))'
> 10000 loops, best of 3: 183 usec per loop
> $ python3 -m timeit 't = list(range(10000))'
> 10000 loops, best of 3: 174 usec per loop
> $ python3 -m timeit 't = tuple(range(10000000))'
> 10 loops, best of 3: 323 msec per loop
> $ python3 -m timeit 't = list(range(10000000))'
> 10 loops, best of 3: 306 msec per loop
>
> This is probably a result of the use of freelists to avoid
> reallocating the tuple objects, though. I don't see any substantial
> difference in access time:

Whoops. Actually it's a result of the 3-element tuple being a constant
in the code object. If we use the constructor, the difference mostly
goes away.

$ python3 -m timeit 't = tuple(range(1000, 4000, 1000))'
1000000 loops, best of 3: 0.559 usec per loop
$ python3 -m timeit 't = list(range(1000, 4000, 1000))'
1000000 loops, best of 3: 0.585 usec per loop

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Why does argparse return None instead of [] if an append action isn't used? Adam Funk <a24061@ducksburg.com> - 2015-01-09 14:44 +0000
  Re: Why does argparse return None instead of [] if an append action isn't used? Skip Montanaro <skip.montanaro@gmail.com> - 2015-01-09 08:57 -0600
    Re: Why does argparse return None instead of [] if an append action isn't used? Adam Funk <a24061@ducksburg.com> - 2015-01-09 15:25 +0000
  Re: Why does argparse return None instead of [] if an append action isn't used? Ned Batchelder <ned@nedbatchelder.com> - 2015-01-09 10:12 -0500
    Re: Why does argparse return None instead of [] if an append action isn't used? Adam Funk <a24061@ducksburg.com> - 2015-01-26 13:43 +0000
      Re: Why does argparse return None instead of [] if an append action isn't used? Peter Otten <__peter__@web.de> - 2015-01-26 15:04 +0100
        Re: Why does argparse return None instead of [] if an append action isn't used? Adam Funk <a24061@ducksburg.com> - 2015-01-26 15:50 +0000
          Re: Why does argparse return None instead of [] if an append action isn't used? Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-26 09:13 -0700
            Re: Why does argparse return None instead of [] if an append action isn't used? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-01-26 18:29 +0200
              Re: Why does argparse return None instead of [] if an append action isn't used? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-26 17:18 +0000
              Re: Why does argparse return None instead of [] if an append action isn't used? Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-26 11:23 -0700
              Re: Why does argparse return None instead of [] if an append action isn't used? Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-26 11:26 -0700
  Re: Why does argparse return None instead of [] if an append action isn't used? Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2015-01-09 16:50 +0100
    Re: Why does argparse return None instead of [] if an append action isn't used? Adam Funk <a24061@ducksburg.com> - 2015-01-26 13:43 +0000

csiph-web