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: 528 usec per loop
You are quite right, Gregory, my timings are way off. I have figured out my mistake. Paul's function is a generator. Unlike a normal function, when you call a generator function, it does not actually run the entire function, it simply returns a generator object. It only runs when you iterate over it until it is exhausted. I was effectively measuring how long it took to *create* the generator, not iterate over it. Thanks for correcting me. Frank -- http://mail.python.org/mailman/listinfo/python-list