/* ** $XConsortium: tests.c,v 1.20 91/06/08 18:57:07 rws Exp $ ** */ #include #include #include #include #include #include #include "xgc.h" #ifdef SVR4 #define SYSV #endif #ifndef SYSV #include #include #endif #ifndef PI #define PI 3.14159265 #endif #ifdef SYSV #define random lrand48 #endif #ifndef sgi extern long random(); #endif extern XStuff X; extern Widget result; extern void print_if_recording(); void show_result(); /* timer(flag) ** ----------- ** When called with StartTimer, starts the stopwatch and returns nothing. ** When called with EndTimer, stops the stopwatch and returns the time ** in microseconds since it started. ** ** Uses rusage() so we can subtract the time used by the system and user ** from our timer, and just concentrate on the time used in the X calls. */ static long timer(flag) int flag; { #ifndef SYSV static struct timeval starttime; /* starting time for gettimeofday() */ struct timeval endtime; /* ending time for gettimeofday() */ static struct rusage startusage; /* starting time for getrusage() */ struct rusage endusage; /* ending time for getrusage() */ struct timezone tz; /* to make gettimeofday() happy */ long elapsedtime; /* how long since we started the timer */ switch (flag) { case StartTimer: /* store initial values */ gettimeofday(&starttime,&tz); getrusage(RUSAGE_SELF,&startusage); return((long) NULL); case EndTimer: gettimeofday(&endtime,&tz); /* store final values */ getrusage(RUSAGE_SELF,&endusage); /* all the following line does is use the formula elapsed time = ending time - starting time, but there are three different timers and two different units of time, ack... */ elapsedtime = (long) ((long) ((endtime.tv_sec - endusage.ru_utime.tv_sec - endusage.ru_stime.tv_sec - starttime.tv_sec + startusage.ru_utime.tv_sec + startusage.ru_stime.tv_sec)) * 1000000) + (long) ((endtime.tv_usec - endusage.ru_utime.tv_usec - endusage.ru_stime.tv_usec - starttime.tv_usec + startusage.ru_utime.tv_usec + startusage.ru_stime.tv_usec)); return(elapsedtime); default: fprintf(stderr,"Invalid flag in timer()\n"); return((long) NULL); } #else static long starttime; switch (flag) { case StartTimer: time(&starttime); return((long) NULL); case EndTimer: return( (time(NULL) - starttime) * 1000000); default: fprintf(stderr,"Invalid flag in timer()\n"); return((long) NULL); } #endif } void copyarea_test() { int num_copies = 200; int i; long totaltime; char buf[80]; num_copies *= X.percent; XSetFillStyle(X.dpy,X.miscgc,FillTiled); XFillRectangle(X.dpy,X.win,X.miscgc,0,0,400,400); XSync(X.dpy,0); timer(StartTimer); for (i=0;i