Bengt Richter wrote:
On 5 Sep 2005 07:27:41 -0700, Paul McGuire [EMAIL PROTECTED] wrote:
I still think there are savings to be had by looping inside the
try-except block, which avoids many setup/teardown exception handling
steps. This is not so pretty in another way (repeated while on
ABO [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
There are other optimisations that could be applied that make this
code faster but uglier. For example, putting another while True: loop
inside the try block to avoid the try block setup each iteration.
In CPython, 'setting up'
Terry -
If setting up a try-block is as fast (or takes as long) as one
iteration loop, then wont putting a try-block inside a loop double the
execution time?
-- Paul
--
http://mail.python.org/mailman/listinfo/python-list
Paul McGuire [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Terry -
If setting up a try-block is as fast (or takes as long) as one
iteration loop, then wont putting a try-block inside a loop double the
execution time?
It will double (more or less) the loop overhead. The effect
On 5 Sep 2005 07:27:41 -0700, Paul McGuire [EMAIL PROTECTED] wrote:
I still think there are savings to be had by looping inside the
try-except block, which avoids many setup/teardown exception handling
steps. This is not so pretty in another way (repeated while on
check()), but I would be
On Mon, 05 Sep 2005 21:39:31 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:
On 5 Sep 2005 07:27:41 -0700, Paul McGuire [EMAIL PROTECTED] wrote:
I still think there are savings to be had by looping inside the
try-except block, which avoids many setup/teardown exception handling
steps. This is not
Paul McGuire wrote:
I still think there are savings to be had by looping inside the
try-except block, which avoids many setup/teardown exception handling
steps. This is not so pretty in another way (repeated while on
check()), but I would be interested in your timings w.r.t. your current
I still think there are savings to be had by looping inside the
try-except block, which avoids many setup/teardown exception handling
steps. This is not so pretty in another way (repeated while on
check()), but I would be interested in your timings w.r.t. your current
code.
def loop(self):
Raymond Hettinger posted this recipe to the Python Cookbook. I've not
tried it myself, but it sounds like what you're looking for.
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940
-- Paul
--
http://mail.python.org/mailman/listinfo/python-list
This isn't much prettier, but what if you extract the try-except
overhead out from the while loop? You only expect the exception to
fire one time, at the end of the list. You can also eliminate any
localization of variables for calls that are not called in the loop,
such as self_pool (which does
[EMAIL PROTECTED] writes:
However, it is very ugly. Does anyone have any tips on how I could get
this optimisation to occor magically, via a decorator perhaps?
Have you tried psyco?
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940
For an even bigger improvement (in general), look at psyco:
http://psyco.sourceforge.net/.
Tim Delaney
--
http://mail.python.org/mailman/listinfo/python-list
I guess it is hard to see what the code is doing without a complete
example.
The StopIteration is actually raised by task.next(), at which point
task is removed from the list of generators (self.pool). So the
StopIteration can be raised at any time.
The specific optimisation I am after, which
Yes. It slows down the loop when there are only a few iterators in the
pool, and speeds it up when there are 2000.
My use case involves 1000 iterators, so psyco is not much help. It
doesn't solve the magic creation of locals from instance vars either.
Sw.
--
[EMAIL PROTECTED] writes:
My use case involves 1000 iterators, so psyco is not much help. It
doesn't solve the magic creation of locals from instance vars either.
How about using __slots__ to put those instance vars at fixed offsets
in the pool object (self then needs to be a new-style class
def loop(self):
self_pool = self.pool
self_call_exit_funcs = self.call_exit_funcs
self_pool_popleft = self.pool.popleft
self_pool_append = self.pool.append
check = self.pool.__len__
while check() 0:
task = self_pool_popleft()
Psyco actually slowed down the code dramatically.
I've fixed up the code (replaced the erroneous return statement) and
uploaded the code for people to examine:
The test code is here: http://metaplay.dyndns.org:82/~xerian/fibres.txt
These are the run times (in seconds) of the test file.
without
17 matches
Mail list logo