clock_gettime example 사용 예제 CentOS8 에서 테스트 함
/*------------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
typedef unsigned long long int tick64_t;
typedef unsigned long int tick32_t;
tick32_t get_tick_count();
tick64_t get_tick_count64();
int main()
{
tick64_t tick64;
tick32_t tick32;
tick64 = get_tick_count64();
tick32 = get_tick_count();
printf("tick64 = %lld\n", tick64);
printf("tick32 = %lld\n", tick32);
return 0;
}
tick32_t get_tick_count()
{
tick32_t tick = 0ul;
#if defined(WIN32) || defined(WIN64)
tick = GetTickCount();
#else
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
tick = (tp.tv_sec*1000ul) + (tp.tv_nsec/1000ul/1000ul);
#endif
return tick;
}
tick64_t get_tick_count64()
{
tick64_t tick = 0ull;
#if defined(WIN32) || defined(WIN64)
tick = GetTickCount64();
#else
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
tick = (tp.tv_sec*1000ull) + (tp.tv_nsec/1000ull/1000ull);
#endif
return tick;
}
/*------------------------------------------------------------------------------*/
결과
'C, C++' 카테고리의 다른 글
SHA 512 , C++ (0) | 2021.08.19 |
---|---|
Setting PATH and LD_LIBRARY_PATH for the bash shell (0) | 2020.05.20 |
Stack Size 조절 (0) | 2019.04.23 |
Setting PATH and LD_LIBRARY_PATH for the bash shell (0) | 2019.01.23 |
-Wdeprecated-declarations 경고 없애기 (0) | 2019.01.23 |