Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python3': 0.07; '2000,': 0.09; 'lawrence': 0.09; 'objects,': 0.09; 'subject:None': 0.09; 'subject:Why': 0.09; 'jan': 0.12; '10000000': 0.16; '100000000': 0.16; '323': 0.16; 'subject: \n ': 0.16; 'subject:argparse': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'creating': 0.23; 'mon,': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'though.': 0.31; 'time:': 0.31; 'tuples': 0.31; 'probably': 0.32; 'anybody': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'accessing': 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'list,': 0.38; 'to:addr:python.org': 0.39; 'first': 0.61; 'confirm': 0.64; '10000': 0.68; '26,': 0.68; '2015': 0.84; 'us?': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=D2yZjYKCJUS5tkbRoE/IhETX2zx1yz/MYn7tfIZnlGs=; b=BE9O3OwtuJPTp9nrzZEjDS8EqqxCUE/EDMEG6k4Zr9MsNXxWipgr2nyd8Msb3FkXfn bds6QujFo1zI43P9hXD1JVxey3UGQfIPVnwUl08bibuq98J3tb2izJYPFPqIQEYEp53K cNnZ4ce/CgXL0TArjUiAr/kZF9uqtATI6no8mkq5FBpwMiM7sNG/oB/az18WyvvYwdvJ o+b4X9XH1+I43xM0gqvX2ksHuHlRYoB5BJP2S4bxny3iKQzZ1whuUSRfwkt/x7urpTTx SXvVBl35lEQPen499MXCpsfbWW26UkHx0XcYgsfsSFtsY4zPLZiGkUfUQokUOKO3qpCH RcRg== X-Received: by 10.66.153.48 with SMTP id vd16mr36176176pab.146.1422296655802; Mon, 26 Jan 2015 10:24:15 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: <8tshpbxjvv.ln2@news.ducksburg.com> From: Ian Kelly Date: Mon, 26 Jan 2015 11:23:34 -0700 Subject: Re: Why does argparse return None instead of [] if an append action isn't used? To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1422296665 news.xs4all.nl 2949 [2001:888:2000:d::a6]:41228 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:84614 On Mon, Jan 26, 2015 at 10:18 AM, Mark Lawrence wrote: > IIRC, and probably from this list, creating tuples is way faster than > creating lists, but accessing items is slower. Can anybody confirm this for > us? The first seems to be true as long as the tuples are small. $ 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: $ python3 -m timeit -s 't = tuple(range(10000))' 't[5000]' 10000000 loops, best of 3: 0.0316 usec per loop $ python3 -m timeit -s 't = list(range(10000))' 't[5000]' 10000000 loops, best of 3: 0.0318 usec per loop $ python3 -m timeit -s 't = tuple(range(10000))' 'for x in t: pass' 10000 loops, best of 3: 112 usec per loop $ python3 -m timeit -s 't = list(range(10000))' 'for x in t: pass' 10000 loops, best of 3: 113 usec per loop