Сабж. Пример кода:
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <inttypes.h>
inline uint64_t gettime1(void)
{
struct timespec tm;
clock_gettime(CLOCK_REALTIME, &tm);
return (uint64_t)tm.tv_sec * 1000000000ull + tm.tv_nsec;
}
inline uint64_t gettime2(void)
{
struct timeval tm;
gettimeofday(&tm, NULL);
return (tm.tv_sec * 1000000 + tm.tv_usec) * 1000ULL;
}
int main(void)
{
uint64_t b = gettime2();
uint64_t a = gettime1();
printf("%"PRIu64"\n""%"PRIu64"\n", a, b);
return 0;
}
Выхлоп strace
strace -c ./a.out
1433046804438570051
1433046804438568000
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
28.99 0.000040 5 8 mmap
17.39 0.000024 6 4 mprotect
13.04 0.000018 6 3 3 access
10.87 0.000015 8 2 write
7.97 0.000011 6 2 open
7.97 0.000011 11 1 munmap
5.80 0.000008 3 3 fstat
2.90 0.000004 2 2 close
2.17 0.000003 3 1 read
1.45 0.000002 2 1 arch_prctl
0.72 0.000001 1 1 brk
0.72 0.000001 1 1 execve
------ ----------- ----------- --------- --------- ----------------
100.00 0.000138 29 3 total
В чем может быть проблема?