/* * This program is under the GNU GPL. * Use at your own risk. * * written by David Bucciarelli (tech.hmw@plus.it) * Humanware s.r.l. */ #include #include #include #include #include typedef struct { char *name; char *unit; void (*init)(void); int (*run)(int, int); int type; int numsize; int size[10]; } benchmark; static int frontbuffer=1; /***************************************************************************/ static void init_test01(void) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-0.5,639.5,-0.5,479.5); glMatrixMode(GL_MODELVIEW); glShadeModel(GL_FLAT); glDisable(GL_DEPTH_TEST); glClearColor(0.0,0.1,1.0,0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,0.0,0.0); } /* ARGSUSED */ static int test01(int size, int num) { int x,y; glBegin(GL_POINTS); for(y=0;yinit(); stime=glutGet(GLUT_ELAPSED_TIME); dtime=0.0; calibnum=0; while(dtime<2.0) { bmark->run(0,1); glFinish(); etime=glutGet(GLUT_ELAPSED_TIME); dtime=(etime-stime)/1000.0; calibnum++; } glPopAttrib(); fprintf(stderr,"Elapsed time for the calibration test (%d): %f\n",calibnum,dtime); num=(int)((BMARKS_TIME/dtime)*calibnum); if(num<1) num=1; fprintf(stderr,"Selected number of benchmark iterations: %d\n",num); mintime=HUGE_VAL; maxtime=-HUGE_VAL; for(tottime=0.0,j=0;j<5;j++) { glPushAttrib(GL_ALL_ATTRIB_BITS); bmark->init(); stime=glutGet(GLUT_ELAPSED_TIME); numelem=bmark->run(0,num); glFinish(); etime=glutGet(GLUT_ELAPSED_TIME); glPopAttrib(); dtime=(etime-stime)/1000.0; tottime+=dtime; fprintf(stderr,"Elapsed time for run %d: %f\n",j,dtime); if(dtimemaxtime) maxtime=dtime; } tottime-=mintime+maxtime; fprintf(stdout,"%s\n%f %s/sec",bmark->name,numelem/(tottime/3.0),bmark->unit); if(bmark->type==3) fprintf(stdout,", MPixel Fill/sec: %f\n\n", (numelem*bmark->size[0]*(float)bmark->size[0])/(1000000.0*tottime/3.0)); else fprintf(stdout,"\n\n"); } /***************************************************************************/ static void dotest1param(benchmark *bmark) { float stime,etime,dtime,tottime,maxtime,mintime; int num,numelem,calibnum,j,k; fprintf(stdout,"%s\n",bmark->name); for(j=0;jnumsize;j++) { fprintf(stderr,"Current size: %d\n",bmark->size[j]); glPushAttrib(GL_ALL_ATTRIB_BITS); bmark->init(); stime=glutGet(GLUT_ELAPSED_TIME); dtime=0.0; calibnum=0; while(dtime<2.0) { bmark->run(bmark->size[j],1); glFinish(); etime=glutGet(GLUT_ELAPSED_TIME); dtime=(etime-stime)/1000.0; calibnum++; } glPopAttrib(); fprintf(stderr,"Elapsed time for the calibration test (%d): %f\n",calibnum,dtime); num=(int)((BMARKS_TIME/dtime)*calibnum); if(num<1) num=1; fprintf(stderr,"Selected number of benchmark iterations: %d\n",num); mintime=HUGE_VAL; maxtime=-HUGE_VAL; for(numelem=1,tottime=0.0,k=0;k<5;k++) { glPushAttrib(GL_ALL_ATTRIB_BITS); bmark->init(); stime=glutGet(GLUT_ELAPSED_TIME); numelem=bmark->run(bmark->size[j],num); glFinish(); etime=glutGet(GLUT_ELAPSED_TIME); glPopAttrib(); dtime=(etime-stime)/1000.0; tottime+=dtime; fprintf(stderr,"Elapsed time for run %d: %f\n",k,dtime); if(dtimemaxtime) maxtime=dtime; } tottime-=mintime+maxtime; fprintf(stdout,"SIZE=%03d => %f %s/sec",bmark->size[j],numelem/(tottime/3.0),bmark->unit); if(bmark->type==2) fprintf(stdout,", MPixel Fill/sec: %f\n", (numelem*bmark->size[j]*bmark->size[j]/2)/(1000000.0*tottime/3.0)); else fprintf(stdout,"\n"); } fprintf(stdout,"\n\n"); } /***************************************************************************/ static void display(void) { int i; if(frontbuffer) glDrawBuffer(GL_FRONT); else glDrawBuffer(GL_BACK); for(i=0;i