Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19282
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <g.rodola@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'socket': 0.04; 'francis': 0.07; 'subject:while': 0.07; 'python': 0.08; 'difference,': 0.09; 'erik': 0.09; 'iterate': 0.09; 'loop.': 0.09; 'received:209.85.210.174': 0.13; 'received:mail- iy0-f174.google.com': 0.13; 'cc:addr:python-list': 0.15; 'this:': 0.15; '"while': 0.16; 'latter,': 0.16; 'obviously,': 0.16; 'socket.': 0.16; 'worried': 0.16; 'wrote:': 0.16; '>>>': 0.18; 'example.': 0.18; 'level,': 0.18; '\xa0so': 0.18; 'cc:no real name:2**0': 0.21; 'header:In-Reply-To:1': 0.22; 'obviously': 0.23; '\xa0if': 0.23; 'cc:2**0': 0.25; 'right.': 0.25; 'url:mailman': 0.26; 'url:code': 0.28; 'message-id:@mail.gmail.com': 0.28; 'example': 0.28; 'explicitly': 0.28; 'cc:addr:python.org': 0.29; 'times.': 0.30; 'cases.': 0.30; 'url:listinfo': 0.30; '---': 0.31; 'actually': 0.32; "can't": 0.32; "isn't": 0.32; "won't": 0.33; 'instead': 0.33; 'loop': 0.34; 'majority': 0.34; 'too': 0.34; 'rather': 0.34; 'certain': 0.34; 'ca,': 0.34; 'changing': 0.34; 'from:charset:iso-8859-1': 0.34; '...': 0.35; 'something': 0.35; 'file': 0.35; 'url:python': 0.36; 'executing': 0.36; 'minimal': 0.36; 'things,': 0.36; 'but': 0.37; "there's": 0.37; 'received:google.com': 0.37; 'using': 0.37; 'some': 0.38; 'received:209.85': 0.38; 'think': 0.38; 'speak': 0.38; 'skip:\xa0 10': 0.38; 'url:org': 0.39; 'point': 0.39; 'either': 0.39; 'being': 0.39; 'received:209': 0.39; 'subject:: ': 0.39; 'difference': 0.40; 'most': 0.60; 'chance': 0.62; 'url:p': 0.62; 'skip:1 10': 0.63; 'overall': 0.66; 'usa': 0.66; 'friend': 0.69; 'with,': 0.73; 'defensive': 0.84; 'imagine,': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=BMc9Knb8HmI/eyZNv8/u7Fletmkw0pT5TyEYfvLAI1k=; b=qvUJ3nhnMThcHRP+/Qttdep3HAaL3CqaitXjjGroffHOOwqisM8p0wc0y59K1XSFT6 zx2fPgEA88C8o72wxebRKBEMWcqXDTnImM/Xkk3W7lZFwilh7OO9K2m3CGLhTOeK6L1F loEZ4tM99AaSeqFl4ipy1f9RPBNCnvH0MQ9SM= |
| MIME-Version | 1.0 |
| In-Reply-To | <4v6dnYAfTu69LIDSnZ2dnUVZ5r6dnZ2d@giganews.com> |
| References | <4F1AC1D4.2080402@gmail.com> <mailman.4909.1327157944.27778.python-list@python.org> <pL-dnUjq2eH3t4bSnZ2dnUVZ5vudnZ2d@giganews.com> <mailman.4967.1327336916.27778.python-list@python.org> <4v6dnYAfTu69LIDSnZ2dnUVZ5r6dnZ2d@giganews.com> |
| Date | Mon, 23 Jan 2012 21:20:23 +0100 |
| Subject | Re: while True or while 1 |
| From | Giampaolo Rodolà <g.rodola@gmail.com> |
| To | Erik Max Francis <max@alcyone.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4978.1327350029.27778.python-list@python.org> (permalink) |
| Lines | 72 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1327350029 news.xs4all.nl 6928 [2001:888:2000:d::a6]:50162 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:19282 |
Show key headers only | View raw
Il 23 gennaio 2012 20:12, Erik Max Francis <max@alcyone.com> ha scritto: > Giampaolo Rodolà wrote: >> >> Il 21 gennaio 2012 22:13, Erik Max Francis <max@alcyone.com> ha scritto: >>> >>> The real reason people still use the `while 1` construct, I would >>> imagine, >>> >>> is just inertia or habit, rather than a conscious, defensive decision. >>> If >>> it's the latter, it's a case of being _way_ too defensive. >> >> >> It's also because while 1 is faster: > > ... >> >> while True: 1.41121292114 >> while 1: 1.07101011276 >> >> Most of the times tha't won't make any noticeable difference, but it's >> also true that certain while loops are going to iterate milions of >> times. >> Think about receiving a 10 GB file by using a socket. You'd tipically >> have something like this: >> >> while 1: >> chunk = sock.recv(1024): >> if not chunk: >> break >> ... >> >> Now, that's a case where I (personally) want to explicitly use "while >> >> 1" instead of "while True". > > > Such a loop would obviously be I/O-bound, not CPU-bound. So changing the > form of the while loop would make minimal difference to its overall > performance. It'd be spending the vast majority of its time blocked at the > OS socket level, not executing the condition of the while loop. > > As with most of these things, if one is this worried about performance, then > either Python was the wrong choice to begin with, or there's a good chance > that you're worried about something that isn't actually where the bottleneck > is in the first place. > > > -- > Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/ > San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Jabber erikmaxfrancis > Think twice before you speak to a friend in need. > -- Ambrose Bierce > -- > http://mail.python.org/mailman/listinfo/python-list Obviously, you're right. I picked up the wrong example. My point is 1.41121292114 vs 1.07101011276 *might* make some difference in certain cases. I just can't come up with a good example where that would be justified. =) --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ http://code.google.com/p/pysendfile/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: while True or while 1 Chris Angelico <rosuav@gmail.com> - 2012-01-22 01:59 +1100
Re: while True or while 1 Erik Max Francis <max@alcyone.com> - 2012-01-21 13:13 -0800
Re: while True or while 1 Chris Angelico <rosuav@gmail.com> - 2012-01-22 09:13 +1100
Re: while True or while 1 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-22 05:25 +0000
Re: while True or while 1 Dan Sommers <dan@tombstonezero.net> - 2012-01-22 16:05 +0000
Re: while True or while 1 alex23 <wuwei23@gmail.com> - 2012-01-22 19:55 -0800
Re: while True or while 1 Dave Angel <d@davea.name> - 2012-01-23 08:02 -0500
Re: while True or while 1 Hrvoje Niksic <hniksic@xemacs.org> - 2012-01-23 14:28 +0100
Re: while True or while 1 Dave Angel <d@davea.name> - 2012-01-23 13:33 -0500
Re: while True or while 1 MRAB <python@mrabarnett.plus.com> - 2012-01-22 16:13 +0000
Re: while True or while 1 Grant Edwards <invalid@invalid.invalid> - 2012-01-23 15:51 +0000
Re: while True or while 1 Giampaolo Rodolà <g.rodola@gmail.com> - 2012-01-23 17:41 +0100
Re: while True or while 1 Erik Max Francis <max@alcyone.com> - 2012-01-23 11:12 -0800
Re: while True or while 1 Giampaolo Rodolà <g.rodola@gmail.com> - 2012-01-23 21:20 +0100
Re: while True or while 1 Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-23 10:39 -0700
Re: while True or while 1 Evan Driscoll <edriscoll@wisc.edu> - 2012-01-23 12:05 -0600
Re: while True or while 1 Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-01-23 20:50 +0000
Re: while True or while 1 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-23 14:42 -0800
Re: while True or while 1 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-23 14:42 -0800
Re: while True or while 1 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-24 03:37 +0000
csiph-web