Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4a.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python3': 0.07; '2000,': 0.09; 'objects,': 0.09; 'subject:None': 0.09; 'subject:Why': 0.09; 'jan': 0.12; 'mostly': 0.14; '10000000': 0.16; '100000000': 0.16; '323': 0.16; 'subject: \n ': 0.16; 'subject:argparse': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'mon,': 0.24; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'away.': 0.31; 'constant': 0.31; 'object.': 0.31; 'though.': 0.31; 'time:': 0.31; 'probably': 0.32; 'received:google.com': 0.35; 'subject:?': 0.36; 'being': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'ian': 0.60; '10000': 0.68; '26,': 0.68; '2015': 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=VUgfj/j+LWC1JuAPQNRDQWPJ1PIzU9wAZxbC7R8T7Ro=; b=YO3RUR8Np5pjDA+nAfT3vi143rtM3y6+FXlXbjtG4Th352jVR1KBMYLbDavAh0hkVs 3Qwpfkisx8TazLkItXS22BZkSn98TqWhNvB0RE4/ub2sN3QtbkIxaYhipoQOE8yMQEaS qU/Ol33EOKx/XhxFwSqvuWMD6qJPBmJ4ZHW1C8zUfmFbNA/H5vbWVDsFBtZxg8ESUxqG iIYdnXA/xGLKBzuDDKXDIwI9yMR0YoCAXdKeK7sJcWayMjFUJg38GjVaW++8teTZyLGO ZMUcn1dMN6j6OAwFTgWRhFvw/6tKvAmroCcmJ7O2Yn4aH9dbQITWqPHoDQsF0uF0aZPO zJPw== X-Received: by 10.66.120.109 with SMTP id lb13mr37190423pab.66.1422296834553; Mon, 26 Jan 2015 10:27:14 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: <8tshpbxjvv.ln2@news.ducksburg.com> From: Ian Kelly Date: Mon, 26 Jan 2015 11:26:33 -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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1422296837 news.xs4all.nl 2829 [2001:888:2000:d::a6]:46368 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:84615 On Mon, Jan 26, 2015 at 11:23 AM, Ian Kelly 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