[Tutor] iteration controll.
Scot W. Stevenson
scot@possum.in-berlin.de
Wed, 28 Aug 2002 14:54:44 +0200
Hello Thomi,
if I understand your problem correctly, you have a series of instructions
that take a certain amount of time, say inst_time, and want to insert a
pause of a certain length, say pause_time, so that together they either
add up to one second (slowest) or 1/80 of a second (fastest), which we
could call iterations per second, or iter_freq.
So what we should be looking at is some formula such as
pause_time = (1 - inst_time) / iter_freq
with pause_time in seconds. You don't know inst_time beforehand, you say;
my suggestion would be to calculate it at the start of the program by
running a few 100 or 1,000 iterations (the more the better, to average out
system load factors). Then you use the above formula to recalculate the
pause depending on the slider value (which gives you iter_freq).
Since you are talking about "wall clock time" and I see from your signature
that you're running Linux, time.time() is IFAIK the best way to do the
timing of the iterations (this, at least, is what Tim Peters says in the
"Python Cookbook"). To get the pause itself, you can use time.sleep(),
which dozes off in seconds, and add this to the iteration loop.
It might help if you post the relevant part of the code here, so that
people who do this all the time can give even better suggestions...
Y, Scot
--
Scot W. Stevenson wrote me on Wednesday, 28. Aug 2002 in Zepernick, Germany
on his happy little Linux system that has been up for 1715 hours
and has a CPU that is falling asleep at a system load of 0.00.