TIL/os
프로세스 실행 시간 체크
DingCoDing
2022. 10. 3. 22:21
반응형
#include <stdio.h>
#include <unistd.h>
#include <sys/times.h>
#include <limits.h>
#include <stdlib.h>
#include <time.h>
int main() {
int i;
time_t t;
struct tms mytms;
clock_t t1, t2;
if((t1 = times(&mytms)) == -1){
perror("times 1");
exit(1);
}
for(i = 0; i< 99999999; i++)
time(&t);
if((t2 = times(&mytms)) == -1){
perror("times 2");
exit(1);
}
printf("Real time : %.1f sec\n", (double)(t2- t1)/ CLK_TCK);
printf("User time : %.1f sec\n", (double)mytms.tms_utime / CLK_TCK);
printf("System time : %.1f sec\n", (double)mytms.tms_stime/ CLK_TCK);
return 0;
}
--output--
Real time : 5.3 sec
User time : 5.2 sec
System time : 0.0 sec
반응형