C Func clock - sonkoni/Koni-Wiki GitHub Wiki
프로세스를 수행한 시점부터 흐른 시간
clock_t clock(void);
// 32비트 integer 값으로 반환되며 CLOCKS_PER_SEC(1000000)를 이용해 초 단위로 변환 가능하다.
// clock 을 이용해 2147초(약 36분)까지 측정 가능하다.보통은 unistd.h 에 있는 sleep 을 이용하지만, 이를 수동으로 구현할 수도 있다.
#include <stdio.h>
#include <time.h>
void delay(unsigned int sec) {
clock_t ticks1 = clock();
clock_t ticks2 = ticks1;
while ((ticks2 / CLOCKS_PER_SEC - ticks1 / CLOCKS_PER_SEC) < (clock_t)sec) {
ticks2 = clock();
}
// 초 : ticks2 / CLOCKS_PER_SEC
}
int main(int argc, char *argv[]) {
printf("시작\n");
delay(3);
printf("종료\n");
return 0;
}