swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Optimizing heatbugs in Obj-C


From: Paul E. Johnson
Subject: Optimizing heatbugs in Obj-C
Date: Mon, 10 Apr 2000 21:44:40 -0500

At Swarmfest Marcus talked about making efficient code and I've followed
a bit of his example to make Obj-C Heatbugs run faster.  The benefit of
this effort is the new HeatSpace.m file I deposited here:
http://lark.cc.ukans.edu/~pauljohn/Swarm/MySwarmCode/HeatSpace.m

If you take the original Heatbugs, and run to measure time, in the batch
mode,
time ./heatbugs -b

Then drop in this new HeatSpace.m, you will see the duration of the run
drops approximately 50%.  But don't just believe me, here are the words
of one happy test customer at the University of Indiana: "I see a
reduction from 19.99 s to 8.46 seconds".

The speedup here is due mainly to getting rid of a swarm list and
replacing it with a sharper use of arrays in the findExtremeValue
method.  Putting things into and geting them out of a list is
comparatively slow.  Also, since modulus calculations are comparatively
slow, I've designed this to avoid them were possible, checking to see if
a point is on the edge and  only then is the modulus used to get
coordinates for neighboring squares.  Even so, there is some
inefficiency in the algorithm because the value at the current square is
calculated twice.

I left in some comments about optimizations that I tried and failed. 
FOr example, I thought at the outset that the model would work faster if
the lattice underlying the heatspace could be accessed directly with
pointers, the way it is done in the swarm libraries themselves.  I tried
to speed things up with these risky adjustments:
*discrete2dSiteAt(newLattice,offsets,x,y)=(id) heatHere;
but I found that, if anything, these made the model slower than the
saver Obj-c get methods.

I found a study of Marcus's fast code for Java Heatbugs to be very
instructive and if any of you have comparable tips about writing faster
models, I would be glad to hear them. I guess I've said that before

-- 
Paul E. Johnson                         email: address@hidden
Dept. of Political Science              http://lark.cc.ukans.edu/~pauljohn
University of Kansas                    Office: (785) 864-9086
Lawrence, Kansas 66045                  FAX: (785) 864-5700

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]