Re: Magic Optimisation

2005-09-14 Thread ABO
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

Re: Magic Optimisation

2005-09-14 Thread Terry Reedy
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'

Re: Magic Optimisation

2005-09-14 Thread Paul McGuire
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

Re: Magic Optimisation

2005-09-14 Thread Terry Reedy
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

Re: Magic Optimisation

2005-09-05 Thread Bengt Richter
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

Re: Magic Optimisation

2005-09-05 Thread Bengt Richter
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

Re: Magic Optimisation

2005-09-05 Thread simonwittber
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

Re: Magic Optimisation

2005-09-05 Thread Paul McGuire
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):

Re: Magic Optimisation

2005-09-05 Thread Paul McGuire
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

Re: Magic Optimisation

2005-09-04 Thread Paul McGuire
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

Re: Magic Optimisation

2005-09-04 Thread Paul Rubin
[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

RE: Magic Optimisation

2005-09-04 Thread Delaney, Timothy (Tim)
[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

Re: Magic Optimisation

2005-09-04 Thread simonwittber
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

Re: Magic Optimisation

2005-09-04 Thread simonwittber
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. --

Re: Magic Optimisation

2005-09-04 Thread Paul Rubin
[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

Re: Magic Optimisation

2005-09-04 Thread simonwittber
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()

Re: Magic Optimisation

2005-09-04 Thread simonwittber
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