Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87570
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.017 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; '16,': 0.03; 'subsequent': 0.05; 'python3': 0.07; 'subject:skip:c 10': 0.09; 'dict': 0.16; 'iterated': 0.16; 'measurement': 0.16; 'once.': 0.16; 'wrote:': 0.18; 'producing': 0.19; 'result.': 0.19; 'mon,': 0.24; 'header :In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; '100000': 0.31; 'once,': 0.31; 'overhead': 0.31; 'run': 0.32; 'received:google.com': 0.35; 'really': 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'expression': 0.60; 'zip': 0.64; 'mar': 0.68; 'frank': 0.68; '2015': 0.84; 'compare:': 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=UmFTfa2aX9ANaiMLEoDbYYiSmym+B5LPjtLvwiAxXzg=; b=QPKpqvKu78KwLJersQh4Yhwn6TbqBXweLRtj2Dd9JDAvCwkvKocm30lIXVQ1ftKT8J mFxp4mb1Mpg7SwSrh4DxcxbbAKOQp7+67RFJcmY53YhnnD95gPwQyZUclw+++qwBS0NG VSw2rZJW12z2akXDk0V4FfbjaE50CBbVuPGZnkVY768PKirDxbKMv0dd2m3f3RI4KdHn ONIPVE3eP+wKRD9HTjDLKYr1IJWNac7aJveFkuG/N/k3HdtzmmBG9kffDHphPXG3GtdG +VEW71+XgAZQP29wfBTXGM+Og8rvNBot9rTvv/9yVHWTJAjj6ZNElZV1PqDg6msMUJ2C jB9Q== |
| X-Received | by 10.70.89.195 with SMTP id bq3mr96799906pdb.138.1426521468266; Mon, 16 Mar 2015 08:57:48 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <me664q$hon$1@ger.gmane.org> |
| References | <mailman.410.1426483550.21433.python-list@python.org> <87fv95fom0.fsf@jester.gateway.sonic.net> <mailman.427.1426494675.21433.python-list@python.org> <87wq2hfibu.fsf@jester.gateway.sonic.net> <me664q$hon$1@ger.gmane.org> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Mon, 16 Mar 2015 09:57:07 -0600 |
| Subject | Re: Dict comprehensions - improvement to docs? |
| To | Python <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.19 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.450.1426521470.21433.python-list@python.org> (permalink) |
| Lines | 26 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1426521470 news.xs4all.nl 2964 [2001:888:2000:d::a6]:51398 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:87570 |
Show key headers only | View raw
On Mon, Mar 16, 2015 at 3:01 AM, Frank Millman <frank@chagford.com> wrote:
> C:\>python -m timeit -s "x = range(65, 91); y = (chr(z) for z in x)"
> "dict(zip(x, y))"
> 100000 loops, best of 3: 11.9 usec per loop
>
> C:\>python -m timeit -s "x = range(65, 91); y = (chr(z) for z in x)" "{a: b
> for a, b in zip(x, y)}"
> 100000 loops, best of 3: 7.24 usec per loop
Since the setup code is only run once, the generator expression used
for y is only iterated over once. On every subsequent loop, zip is
producing an empty result. So this measurement is really just
capturing the overhead of the dict construction. Compare:
$ python3 -m timeit -s "x = range(65, 91); y = (chr(z) for z in x)"
"dict(zip(x,y))"
1000000 loops, best of 3: 0.9 usec per loop
$ python3 -m timeit -s "x = range(65, 91); y = [chr(z) for z in x]"
"dict(zip(x,y))"
100000 loops, best of 3: 2.69 usec per loop
$ python3 -m timeit -s "x = range(65, 91); y = (chr(z) for z in x)"
"{a:b for a,b in zip(x,y)}"
1000000 loops, best of 3: 0.837 usec per loop
$ python3 -m timeit -s "x = range(65, 91); y = [chr(z) for z in x]"
"{a:b for a,b in zip(x,y)}"
100000 loops, best of 3: 2.67 usec per loop
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Dict comprehensions - improvement to docs? "Frank Millman" <frank@chagford.com> - 2015-03-16 07:25 +0200
Re: Dict comprehensions - improvement to docs? Paul Rubin <no.email@nospam.invalid> - 2015-03-15 23:22 -0700
Re: Dict comprehensions - improvement to docs? "Frank Millman" <frank@chagford.com> - 2015-03-16 10:30 +0200
Re: Dict comprehensions - improvement to docs? Paul Rubin <no.email@nospam.invalid> - 2015-03-16 01:38 -0700
Re: Dict comprehensions - improvement to docs? "Frank Millman" <frank@chagford.com> - 2015-03-16 11:01 +0200
Re: Dict comprehensions - improvement to docs? Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-16 09:57 -0600
Re: Dict comprehensions - improvement to docs? Paul Rubin <no.email@nospam.invalid> - 2015-03-16 15:41 -0700
Re: Dict comprehensions - improvement to docs? "Frank Millman" <frank@chagford.com> - 2015-03-17 08:44 +0200
Re: Dict comprehensions - improvement to docs? Lele Gaifax <lele@metapensiero.it> - 2015-03-17 15:06 +0100
Re: Dict comprehensions - improvement to docs? Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-17 09:48 -0600
Re: Dict comprehensions - improvement to docs? "Frank Millman" <frank@chagford.com> - 2015-03-18 10:01 +0200
Re: Dict comprehensions - improvement to docs? Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-18 02:39 -0600
csiph-web