/* nulltime.c Measures the time for a low priority process to execute a certain number of operations. This is used in a pair of runs, one with an unloaded system, and one with a loaded system. Utilization = (1 - unloaded/loaded) x 100 % Written by David Horton 6-Jan-92 */ #include #include #ifndef _INCLUDE_POSIX_SOURCE #define _INCLUDE_POSIX_SOURCE #endif #ifndef _INCLUDE_HPUX_SOURCE #define _INCLUDE_HPUX_SOURCE #endif #include #include #define NICE 19 main (int argc, char *argv[]) { int loops = 10000000; /* basic # loops */ int repeats = 1; /*additional multiplier,if loops insufficient*/ struct timeval now; /* time at the present moment */ struct timeval then; /* when our time expires */ struct timezone us; /* unused */ int l, r; /* counters */ if (argc > 3) { fprintf(stderr,"Usage: %s [loops [2nd_multiplier]]\n", argv[0]); exit (1); } if (argc >= 2) { /* they gave us loops */ loops = atoi(argv[1]); } if (argc >= 3) { /* they gave us repeat */ repeats = atoi(argv[2]); } if (gettimeofday(&then, &us)){ /* what was the time at the start */ perror("gettimeofday"); exit (errno); } # ifdef DEBUG printf("now %d.%6d, then %d.%6d\n", now.tv_sec, now.tv_usec, then.tv_sec, then.tv_usec); # endif if (nice(NICE) < 0) { /* set priority low */ perror("nice"); exit (errno); } for (r = 0; r < repeats; r++) for (l = 0; l < loops; l++) ; if (gettimeofday(&now, &us)){ /* when is that in the future */ perror("gettimeofday"); exit (errno); } if (then.tv_usec > now.tv_usec) { now.tv_usec += 1000000; /* avoid negatives */ now.tv_sec--; } # ifdef DEBUG printf("now %d.%6d, then %d.%6d\n", now.tv_sec, now.tv_usec, then.tv_sec, then.tv_usec); # endif printf("%d.%06d secs for %d x %d operations\n", now.tv_sec - then.tv_sec, now.tv_usec - then.tv_usec, repeats, loops); exit(0); }