Forum unknown
· Programming
Circle Benchmark
1 messages in this thread
OK, for those of you who have wondered about the circle paint routine I used
for my benchmark, here it is. It's just a modified Bresenham routine which
draws line between points reflected across the Y-axis (see Foley & Van Dam,
p. 445):
MichCircle(qrastport,radius,qcx,qcy,color)
struct RastPort *qrastport;
int radius,qcx,qcy,color;
{
register int cx,cy,x,y,d;
register struct RastPort *rastport;
cx = qcx; cy = qcy;
rastport = qrastport;
SetAPen(rastport,color);
x = 0; y = radius; d = 3 – (radius+radius);
while (x<y) {
Move(rastport,cx-x,cy+y); Draw(rastport,cx+x,cy+y);
Move(rastport,cx-y,cy+x); Draw(rastport,cx+y,cy+x);
Move(rastport,cx-x,cy-y); Draw(rastport,cx+x,cy-y);
Move(rastport,cx-y,cy-x); Draw(rastport,cx+y,cy-x);
if (d < 0)
d += (x << 2) + 6;
else {
d += ((x – y) << 2) + 10;
y–;
}
x++;
}
if (x == y) {
Move(rastport,cx-x,cy+y); Draw(rastport,cx+x,cy+y);
Move(rastport,cx-y,cy+x); Draw(rastport,cx+y,cy+x);
Move(rastport,cx-x,cy-y); Draw(rastport,cx+x,cy-y);
Move(rastport,cx-y,cy-x); Draw(rastport,cx+y,cy-x);
}
}
DoCircle(rastport)
struct RastPort *rastport;
{
int i;
int CMax = 200;
struct timeval start,finish;
printf(" paints %d circles in ",2*CMax);
GetTime(&start);
for (i=0; i < CMax; i++) {
MichCircle(rastport,100,200,150,Black);
MichCircle(rastport,100,200,150,White);
}
GetTime(&finish);
delta(&finish,&start); printf("\n");
}
GetTime(ctime)
struct timeval *ctime;
{
DoIO(timerio); /* globally declared as struct timerequest */
ctime->tv_secs = timerio->tr_time.tv_secs;
ctime->tv_micro = timerio->tr.time.tv_micro;
}
delta(finish,start)
struct timeval *finish,*start;
{
ULONG dsec,dmic;
dmic = finish->tv_micro – start->tv_micro;
dsec = finish->tv_secs – start->tv_secs;
if (dmic < 0) {
dmic += 1000000;
dsec–;
}
printf("%d.%d seconds",desc,dmic/100000);
}
Note, before you ask, yes I tried substituting RectFill for each Move/Draw
pair. It was about 25% *slower* (108 seconds instead of 86). Also, I don't
fully trust the timer routine and always verify my timings with a hand-held
stopwatch. All timings were done with a monochrome (single bit-plane)
640×400 (interlaced) display. This was all done under 1.1; I still haven't
tried it out under 1.2 (I have alpha-8). ..bfw..