Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44071
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <skip.montanaro@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.006 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'output': 0.05; '"""': 0.07; 'python': 0.11; '2.7': 0.14; 'random': 0.14; 'array.': 0.16; 'from:addr:pobox.com': 0.16; 'from:addr:skip': 0.16; 'itertools': 0.16; 'numpy': 0.16; 'skip:# 20': 0.16; 'sender:addr:gmail.com': 0.17; 'import': 0.22; 'skip': 0.24; 'this:': 0.26; 'header:In- Reply-To:1': 0.27; 'skip:p 30': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; 'skip:7 10': 0.31; 'run': 0.32; 'objects': 0.35; 'received:google.com': 0.35; 'subject:List': 0.36; 'skip:4 10': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'space': 0.40; 'idiom': 0.84; 'improvement': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=MOLYy+I2xpxf/YnMzt7uTWF7tCMEFA4LL+q37CmMZ8E=; b=mZt/y5ssgniaV6kxh0ap/utNTvA5hd0AJxZvv+nA5MNMpBo/bov8dDRfN0UtWw8B1U 0nMGtNcbUMpL0XxkJunafy8X99uMtBCRDuR6cUCXmTalQc73HCHxTnNLxRnUsfpGHpPd 6tBLt38BNbWUMTbCkzJdNZANREwWll7+TESycuBx+MJksCSG0bQxaaOIuIaVcc1m+4Ji Dn3QSOO3dNybC2tXd+PvhZk/hFEY3BqynUFygP8NbkoZK8qiQxm8cvFw25sR4h8H1XDG L+oSRlBnD/RrMEAf60dZUfED8dRSsMO3f4OYq3lxyKK0d1SuvGebgD/OuC+QjxHAHv5C e2cg== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.37.212 with SMTP id a20mr15590408igk.88.1366639046872; Mon, 22 Apr 2013 06:57:26 -0700 (PDT) |
| Sender | skip.montanaro@gmail.com |
| In-Reply-To | <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> |
| References | <sridnffI6YhxuOjMnZ2dnUVZ7tSdnZ2d@brightview.co.uk> <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> |
| Date | Mon, 22 Apr 2013 08:57:26 -0500 |
| X-Google-Sender-Auth | PxKkKMd8SywiahPa8Zk7JKNiE3Q |
| Subject | Re: List Count |
| From | Skip Montanaro <skip@pobox.com> |
| To | python-list@python.org |
| 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 <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.915.1366639056.3114.python-list@python.org> (permalink) |
| Lines | 40 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1366639056 news.xs4all.nl 2227 [2001:888:2000:d::a6]:53609 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:44071 |
Show key headers only | View raw
Numpy is a big improvement here. In Py 2.7 I get this output if I run
Steven's benchmark:
2.10364603996
3.68471002579
4.01849389076
7.41974878311
10.4202470779
9.16782712936
3.36137390137
(confirming his results). If I then run the numpy idiom for this:
########################
import random
from timeit import Timer
import numpy
sieve = numpy.array([random.random() < 0.5 for i in range(10**7)],
dtype=bool)
setup = """from __main__ import sieve
from itertools import islice
hi = 7*10**6
"""
t1 = Timer("(True == sieve[:hi]).sum()", setup)
print(min(t1.repeat(number=10)))
###########################
I get :
0.344316959381
It likely consumes less space as well, since it doesn't store Python
objects in the array.
Skip
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 12:58 +0100
Re: List Count Dave Angel <davea@davea.name> - 2013-04-22 08:51 -0400
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 14:03 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 14:03 +0100
Re: List Count Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-22 13:13 +0000
Re: List Count Skip Montanaro <skip@pobox.com> - 2013-04-22 08:57 -0500
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 15:15 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-22 16:14 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 16:50 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-22 17:06 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 17:38 +0100
Re: List Count Skip Montanaro <skip@pobox.com> - 2013-04-22 12:48 -0500
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 20:22 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-22 21:18 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 22:25 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-23 00:06 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 07:45 +0100
Re: List Count Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-22 23:28 +0000
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 08:00 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-22 22:03 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 22:32 +0100
Re: List Count Dave Angel <davea@davea.name> - 2013-04-22 21:47 -0400
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 08:02 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 17:38 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 16:50 +0100
Re: List Count Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-22 23:01 +0000
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 08:05 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-23 12:08 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 12:45 +0100
Re: List Count Terry Jan Reedy <tjreedy@udel.edu> - 2013-04-23 15:01 -0400
Re: List Count Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-23 14:49 +0000
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 17:57 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-23 18:45 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 19:30 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-23 20:16 +0100
Re: List Count Terry Jan Reedy <tjreedy@udel.edu> - 2013-04-23 16:00 -0400
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 21:41 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-23 21:38 +0100
Re: List Count Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-24 01:59 +0000
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-24 10:01 +0100
Re: List Count Peter Otten <__peter__@web.de> - 2013-04-22 15:22 +0200
Re: List Count 88888 Dihedral <dihedral88888@googlemail.com> - 2013-04-22 06:36 -0700
csiph-web