1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include <sys/types.h> #include <sys/times.h> main() { struct tms before, after; times(&before); /* ... place code to be timed here ... */ times(&after); printf("User time: %ld seconds\n", after.tms_utime - before.tms_utime); printf("System time: %ld seconds\n", after.tms_stime - before.tms_stime); exit(0); }