Python speed

David Bolen db3l at fitlinxx.com
Wed Jul 11 16:14:33 EDT 2001


jcm <grumble at usa.net> writes:

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

First off, I think your general point that CPU performance can
certainly be a limiting factor in such development is certainly true,
and as with any other resource constraint it needs to be taken into
account during development.

Whether frames-per-second or heartbeat-per-twosecond, the approach is
still basically the same.  What it sounds like you're saying is that
you had 400 monsters, all of which needed some calculation to take
place in time for a 2-second heartbeat of movement.  So you're really
running at .5fps (if you consider a "frame" to be a new state of being
for all the monsters in your system), or that you need to be able to
process monster movement calculations at least at 2s/400 or 5ms each.
That's a max, as you won't have any computation time for anything but
movement at that level.

So that's a fairly tight timeframe, but it's all going to come down to
the algorithm.  Testing with Python 1.5.2 on a 400MHz PIII (so your
PII 266 clearly is slower), a purely simple loop that grabs an object
from a 400 element list and passes it to an empty function takes about
3.6us per cycle.  But you've got most of those 5ms for your own
movement functionality, and I would think that it should still be
doable even in that environment.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list