/***************************************************************************** * * test2.c 2012.01.19 * Make loops a run time variable. * * test2.c 2012.01.15 * Only do a few loops. I want many seperate tasks per second. * I will make a script to call this program zillions of times. * * testtme.c 2008.12.29 * Linux version of simple Doug CPU benchmark program * * testtme.cpp December 28, 1995 Revision 0 / version 2 * time loop counter. * Smythies * testtme.cpp August 24, 1992 Revision 0 / version 1 * read big file check for time anomallies. * Smythies *****************************************************************************/ #include #include #include #include #include #include #include void main(int argc, char **argv){ int i, j, k, loops; double x,y,z; clock_t start, end; struct tms t_start, t_end; long tps; switch(argc){ case 2: loops = atoi(argv[1]); break; default: printf("test2 loops\n"); printf(" run the CPU time waster for loops cycles\n"); exit(-1); } /* endcase */ tps = sysconf(_SC_CLK_TCK); z = 0.0; start = times(&t_start); /* */ for(i = 0; i < loops; i++){ /* waste cpu time */ for(j = 0; j < 100; j++){ /* waste cpu time */ k = (i + j) / 25; x = sin((double) k); y = sqrt(fabs(x)); z = z + y; /* prevent the optimizer from taking out the loop */ } /* endfor */ } /* endfor */ end = times(&t_end); /* */ printf("Elapsed:%10.2f s. ", ((float)(end - start) / (float)(tps))); /* */ printf("user cpu:%10.2f s. ", ((float)(t_end.tms_utime) / (float)(tps))); printf("sys cpu:%10.2f s.\n", ((float)(t_end.tms_stime) / (float)(tps))); /* start = end; /* */ /* return(0); /* */ }