Python speed

Pete Shinners shredwheat at
Wed Jul 11 12:50:48 EDT 2001

> Well, I say this because I've written a mud engine in Python and it's
> slow.  Using this engine on a PII 266 running RedHat 6.1, 400
> wandering monsters (with nothing else going on in the mud) will peg
> the cpu.

the following program will also peg the cpu

while 1: pass


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...

interval = 1.0/30  #30fps
while 1:
    start = time.time()
    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.

anyways, my point is don't write python's speed off for burning
100% cpu. instead you should admire your OS for letting your app
run as efficiently as it does :]

More information about the Python-list mailing list