Re: Speed up this code?

2006-05-28 Thread Miki
Hello Martin, You can use gmpy (http://gmpy.sourceforge.net/) def primes(): n = 2 while 1: yield long(n) n = gmpy.next_prime(n) HTH, Miki http://pythonwise.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Speed up this code?

2006-05-27 Thread Frank Millman
Gregory Petrosyan wrote: > # Paul Rubin's version > [EMAIL PROTECTED]:~$ python -mtimeit "import test2" "test2.primes(1000)" > 100 loops, best of 3: 14.3 msec per loop > > # version from the Cookbook > [EMAIL PROTECTED]:~$ python -mtimeit "import test1" "test1.primes(1000)" > 1000 loops, best of 3

Re: Speed up this code?

2006-05-26 Thread John Machin
On 27/05/2006 6:57 AM, [EMAIL PROTECTED] wrote: > I have tried this comparison, with a version I've modified a bit, I > have encoutered a problem in sieve_all, for example with n=1, I > don't know why: It might have been better use of bandwidth to give details of the problem instead of all th

Re: Speed up this code?

2006-05-26 Thread bearophileHUGS
I have tried this comparison, with a version I've modified a bit, I have encoutered a problem in sieve_all, for example with n=1, I don't know why: def sieve_all(n=100): # yield all primes up to n stream = iter(xrange(2, n)) while True: p = stream.next() yield p

Re: Speed up this code?

2006-05-26 Thread John Machin
On 26/05/2006 11:25 PM, Frank Millman wrote: > [EMAIL PROTECTED] wrote: >> If you are interested in such programs, you can take a look at this one >> too: >> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/366178 >> >> It requires more memory, but it's quite fast. >> >> Bye, >> bearophile >

Re: Speed up this code?

2006-05-26 Thread Gregory Petrosyan
# Paul Rubin's version [EMAIL PROTECTED]:~$ python -mtimeit "import test2" "test2.primes(1000)" 100 loops, best of 3: 14.3 msec per loop # version from the Cookbook [EMAIL PROTECTED]:~$ python -mtimeit "import test1" "test1.primes(1000)" 1000 loops, best of 3: 528 usec per loop -- http://mail.py

Re: Speed up this code?

2006-05-26 Thread Frank Millman
[EMAIL PROTECTED] wrote: > If you are interested in such programs, you can take a look at this one > too: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/366178 > > It requires more memory, but it's quite fast. > > Bye, > bearophile I compared the speed of this one (A) with the speed of

Re: Speed up this code?

2006-05-26 Thread bearophileHUGS
If you are interested in such programs, you can take a look at this one too: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/366178 It requires more memory, but it's quite fast. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Speed up this code?

2006-05-26 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > I'm creating a program to calculate all primes numbers in a range of 0 > to n, where n is whatever the user wants it to be. I've worked out the > algorithm and it works perfectly and is pretty fast, but the one thing > seriously slowing down the program is the following c

Re: Speed up this code?

2006-05-25 Thread aomighty
I got it working using difference() and sets, thanks all! 100,000 takes about 3 times the time of 10,000, which is what my math buddies told me I should be getting, rather than an exponential increase :). Thanks, all! -- http://mail.python.org/mailman/listinfo/python-list

Re: Speed up this code?

2006-05-25 Thread Paul Rubin
[EMAIL PROTECTED] writes: > Does anybody know a faster way to do this? (finding the difference all > items in list a that are not in list b)? >>> a = [3, 7, 16, 1, 2, 19, 13, 4, 0, 8]# random.sample(range(20),10) >>> b = [15, 11, 7, 2, 0, 3, 9, 1, 12, 16] # similar >>> sorted(set

Re: Speed up this code?

2006-05-25 Thread Tim Chase
> def rmlist(original, deletions): >return [i for i in original if i not in deletions] > > original will be a list of odd numbers and deletions will be numbers > that are not prime, thus this code will return all items in original > that are not in deletions. For n > 100,000 or so, the program

Re: Speed up this code?

2006-05-25 Thread Ben Cartwright
[EMAIL PROTECTED] wrote: > I'm creating a program to calculate all primes numbers in a range of 0 > to n, where n is whatever the user wants it to be. I've worked out the > algorithm and it works perfectly and is pretty fast, but the one thing > seriously slowing down the program is the following c

Speed up this code?

2006-05-25 Thread aomighty
I'm creating a program to calculate all primes numbers in a range of 0 to n, where n is whatever the user wants it to be. I've worked out the algorithm and it works perfectly and is pretty fast, but the one thing seriously slowing down the program is the following code: def rmlist(original, deleti