Python speed

jcm grumble at
Wed Jul 11 13:05:11 EDT 2001

Pete Shinners <shredwheat at> wrote:
> the following program will also peg the cpu

> -----------------------------------------------------------
> while 1: pass
> -----------------------------------------------------------

Certainly, there are things you can reasonably expect to see in a mud,
and things you probably won't see.  I believe wandering monsters are
more common than infinite loops.

> does this mean the language isn't up to the task? now
> subtitute any function call for the pass. as long as your
> function is being called often enough for your programs
> needs, then there shouldn't be any trouble.

> so writing "while 1: move_monsters()" will peg the cpu, it
> is not an indication that the program or the language is
> not able to keep up. now of your loop was written something
> like this...

Maybe I should have been more specific (which I wanted to avoid--I
only meant to say that cpu-time can become an issue).  I'm talking
about monsters that move once per heartbeat, which I usually think of
as about once every two seconds.

> interval = 1.0/30  #30fps
> while 1:
>     start = time.time()
>     move_monsters()
>     diff = time.time() - start
>     if diff < interval: time.sleep(interval - diff)

> ...and it still pegs the cpu, then you've got a problem. if
> the cpu is pegged it means the move_monsters is running slower
> than the desired 30fps. if the move_monsters() function runs
> quicker than each desired timeslice, then the program will sleep
> the remaining time, freeing up the cpu.

If you're talking about frames-per-second, then this doesn't sound
like a text-based mud.  I'm not sure if we're thinking in the same

More information about the Python-list mailing list