Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44071
| References | <sridnffI6YhxuOjMnZ2dnUVZ7tSdnZ2d@brightview.co.uk> <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> |
|---|---|
| Date | 2013-04-22 08:57 -0500 |
| Subject | Re: List Count |
| From | Skip Montanaro <skip@pobox.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.915.1366639056.3114.python-list@python.org> (permalink) |
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