/* ** $XConsortium: tests.c,v 1.20 91/06/08 18:57:07 rws Exp $ ** $XFree86: xc/programs/xgc/tests.c,v 1.7 2001/07/25 15:05:23 dawes Exp $ ** */ #include #include #include #include #include #include #include #include "xgc.h" #ifdef SVR4 #define SYSV #endif #if !defined(SYSV) #include #include #endif #ifndef PI #define PI 3.14159265 #endif #ifdef SYSV #define random lrand48 #endif extern XStuff X; extern Widget result; extern void GC_change_font(); 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; { #if !defined(SYSV) static struct timeval starttime; /* starting time for gettimeofday() */ struct timeval endtime; /* ending time for gettimeofday() */ #ifndef __EMX__ static struct rusage startusage; /* starting time for getrusage() */ struct rusage endusage; /* ending time for getrusage() */ #endif 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); #ifndef __EMX__ getrusage(RUSAGE_SELF,&startusage); #endif return((long) NULL); case EndTimer: gettimeofday(&endtime,&tz); /* store final values */ #ifndef __EMX__ getrusage(RUSAGE_SELF,&endusage); #endif /* 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... */ #ifndef __EMX__ 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)); #else elapsedtime = (long)( ((long)endtime.tv_sec-(long)starttime.tv_sec)*1000000 +((long)endtime.tv_usec-(long)starttime.tv_usec)); #endif 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