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

Ian Kelly ian.g.kelly at gmail.com
Mon Jan 26 19:26:33 CET 2015


On Mon, Jan 26, 2015 at 11:23 AM, Ian Kelly <ian.g.kelly at 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



More information about the Python-list mailing list