/* ** */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include #include #include #include #include "xgc.h" #include #ifndef PI #define PI 3.14159265 #endif #ifdef HAVE_LRAND48 #define random lrand48 #endif /* 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(int flag) { 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); } } void copyarea_test(void) { 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