Re: How to let a loop run for a while before checking for break condition?

2006-08-29 Thread Hendrik van Rooyen
Claudio Grondi [EMAIL PROTECTED] wrote: 8- | The test of the counter is what actually slows the loop down. Probably | the test of time slows the loop even more down. Any test slows a loop | down, so the idea here is to get rid of the test what can be done by | interrupting

Re: How to let a loop run for a while before checking for break condition?

2006-08-29 Thread Hendrik van Rooyen
Hendrik van Rooyen [EMAIL PROTECTED] wrote: 8- Here are some more results, three runs without, and three with a comment in the body of the interesting loop: (a summary follows the detail) python junk.py 0x501 Loop 1 Elapsed time is: 31.2168951035 Loop 1

Re: How to let a loop run for a while before checking for break condition?

2006-08-29 Thread Fredrik Lundh
Sorin Schwimmer wrote: I am thinking on something in the following form: code import time import thread delay=True def fn() global delay time.sleep(your_amount_of_time_in_seconds) delay=False thread.start_new_thread(fn,()) while delay: statement 1 statement 2 ...

Re: How to let a loop run for a while before checking for break condition?

2006-08-29 Thread Matimus
Claudio Grondi wrote: Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of instructions which can sure be optimized away is the check for the break

Re: How to let a loop run for a while before checking for break condition?

2006-08-28 Thread Hendrik van Rooyen
Claudio Grondi [EMAIL PROTECTED] Wrote: | Fredrik Lundh wrote: | Diez B. Roggisch wrote: | | A while loop has a condition. period. The only thing to change that is | to introduce a uncoditioned loop, and use self-modifying code to make | it a while-loop after that timer interrupt of yours.

Re: How to let a loop run for a while before checking for break condition?

2006-08-28 Thread Claudio Grondi
Hendrik van Rooyen wrote: Claudio Grondi [EMAIL PROTECTED] Wrote: | Fredrik Lundh wrote: | Diez B. Roggisch wrote: | | A while loop has a condition. period. The only thing to change that is | to introduce a uncoditioned loop, and use self-modifying code to make | it a while-loop

How to let a loop run for a while before checking for break condition?

2006-08-28 Thread Sorin Schwimmer
to Fredrik Lundh I'm afraid Claudio Grondi can't use your solution, as he needs it hosted on Windows, which lacks signal.alarm. to Claudio Grondi How about splitting your loop in two? The first loop would check for your boolean, which is changed by your timer, the second loop will check for your

Re: How to let a loop run for a while before checking for break condition?

2006-08-28 Thread Claudio Grondi
Sorin Schwimmer wrote: to Fredrik Lundh I'm afraid Claudio Grondi can't use your solution, as he needs it hosted on Windows, which lacks signal.alarm. to Claudio Grondi How about splitting your loop in two? The first loop would check for your boolean, which is changed by your timer, the

How to let a loop run for a while before checking for break condition?

2006-08-28 Thread Sorin Schwimmer
I am thinking on something in the following form: code import time import thread delay=True def fn() global delay time.sleep(your_amount_of_time_in_seconds) delay=False thread.start_new_thread(fn,()) while delay: statement 1 statement 2 ... while other_condition: statement 1

Re: How to let a loop run for a while before checking for break condition?

2006-08-28 Thread Claudio Grondi
Sorin Schwimmer wrote: I am thinking on something in the following form: code import time import thread delay=True def fn() global delay time.sleep(your_amount_of_time_in_seconds) delay=False thread.start_new_thread(fn,()) while delay: statement 1 statement 2 ...

Re: How to let a loop run for a while before checking for break condition?

2006-08-28 Thread Steve Holden
Claudio Grondi wrote: Sorin Schwimmer wrote: [...] It doesn't. Claudio Sometimes silence is preferable to a concrete response. It takes less time and occupies less bandwidth. regards Steve who should perhaps have followed his own advice -- Steve Holden +44 150 684 7255 +1 800

How to let a loop run for a while before checking for break condition?

2006-08-27 Thread Claudio Grondi
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of instructions which can sure be optimized away is the check for the break condition, at least within

Re: How to let a loop run for a while before checking for break condition?

2006-08-27 Thread Diez B. Roggisch
Claudio Grondi schrieb: Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of instructions which can sure be optimized away is the check for the break

Re: How to let a loop run for a while before checking for break condition?

2006-08-27 Thread Claudio Grondi
Diez B. Roggisch wrote: Claudio Grondi schrieb: Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of instructions which can sure be optimized away is

Re: How to let a loop run for a while before checking for break condition?

2006-08-27 Thread Diez B. Roggisch
The idea is to speed up a loop by using a timer interrupt interfering with the loop, so that only after the timer interrupt would occur, the loop will start to check its break condition in each iteration. No checking of any kind in the loop should happen up to that time to minimize the

Re: How to let a loop run for a while before checking for break condition?

2006-08-27 Thread Tal Einat
Diez B. Roggisch wrote: The idea is to speed up a loop by using a timer interrupt interfering with the loop, so that only after the timer interrupt would occur, the loop will start to check its break condition in each iteration. No checking of any kind in the loop should happen up to that

Re: How to let a loop run for a while before checking for break condition?

2006-08-27 Thread Fredrik Lundh
Diez B. Roggisch wrote: A while loop has a condition. period. The only thing to change that is to introduce a uncoditioned loop, and use self-modifying code to make it a while-loop after that timer interrupt of yours. or use a timer interrupt to interrupt the loop: import signal, time def

Re: How to let a loop run for a while before checking for break condition?

2006-08-27 Thread Claudio Grondi
Diez B. Roggisch wrote: The idea is to speed up a loop by using a timer interrupt interfering with the loop, so that only after the timer interrupt would occur, the loop will start to check its break condition in each iteration. No checking of any kind in the loop should happen up to that

Re: How to let a loop run for a while before checking for break condition?

2006-08-27 Thread Claudio Grondi
Fredrik Lundh wrote: Diez B. Roggisch wrote: A while loop has a condition. period. The only thing to change that is to introduce a uncoditioned loop, and use self-modifying code to make it a while-loop after that timer interrupt of yours. or use a timer interrupt to interrupt the

Re: How to let a loop run for a while before checking for break condition?

2006-08-27 Thread Diez B. Roggisch
Fredrik Lundh schrieb: Diez B. Roggisch wrote: A while loop has a condition. period. The only thing to change that is to introduce a uncoditioned loop, and use self-modifying code to make it a while-loop after that timer interrupt of yours. or use a timer interrupt to interrupt the

Re: How to let a loop run for a while before checking for break condition?

2006-08-27 Thread Fredrik Lundh
Diez B. Roggisch wrote: No doubt that changing the flag asynchronously is a gain by delegating the timing code to the OS. Yet the while loop still has a condition - you could as well set a flag in the signal handler an do it like this: if the OP is obsessed with performance, why are you

Re: How to let a loop run for a while before checking for break condition?

2006-08-27 Thread Diez B. Roggisch
Fredrik Lundh schrieb: Diez B. Roggisch wrote: No doubt that changing the flag asynchronously is a gain by delegating the timing code to the OS. Yet the while loop still has a condition - you could as well set a flag in the signal handler an do it like this: if the OP is obsessed