1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <sys/types.h> 5 #include <sys/times.h> 6 #include <time.h> 7 8 int main(int argc, char *argv[]) 9 { 10 struct tms before, after; 11 char cmd[10000]; 12 int i; 13 double fudge = 100.0; /* should be CLOCKS_PER_SEC but that gives nonsense */ 14 15 times(&before); 16 17 /* ... place code to be timed here ... */ 18 cmd[0] = 0; 19 for (i = 1; i < argc; i++) 20 sprintf(cmd+strlen(cmd), "%s ", argv[i]); 21 sprintf(cmd+strlen(cmd), "\n"); 22 /* printf("cmd = [%s]\n", cmd); */ 23 system(cmd); 24 25 times(&after); 26 27 fprintf(stderr, "user %6.3f\n", (after.tms_cutime - before.tms_cutime)/fudge); 28 fprintf(stderr, "sys %6.3f\n", (after.tms_cstime - before.tms_cstime)/fudge); 29 30 return 0; 31 } 32